-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-apply #2349 to shilman/refactor-core
This didn't apply at all cleanly as it involved adding code to each framework's `init.js`, which was removed in the refactor. Here we do better; we simply abstract the job of URL<->redux store syncing to the core library.
- Loading branch information
Showing
9 changed files
with
57 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import qs from 'qs'; | ||
import { window } from 'global'; | ||
import { selectStory } from './actions'; | ||
|
||
// Ensure the story in the redux store and on the preview URL are in sync. | ||
// In theory we should listen to pushState events but given it's an iframe | ||
// the user can't actually change the URL. | ||
// We should change this if we support a "preview only" mode in the future. | ||
export default function syncUrlToStore(reduxStore) { | ||
// handle query params | ||
const queryParams = qs.parse(window.location.search.substring(1)); | ||
if (queryParams.selectedKind) { | ||
reduxStore.dispatch(selectStory(queryParams.selectedKind, queryParams.selectedStory)); | ||
} | ||
|
||
reduxStore.subscribe(() => { | ||
const { selectedKind, selectedStory } = reduxStore.getState(); | ||
|
||
const queryString = qs.stringify({ | ||
...queryParams, | ||
selectedKind, | ||
selectedStory, | ||
}); | ||
window.history.pushState({}, '', `?${queryString}`); | ||
}); | ||
} |