Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call __reload hook with deletedModule #23

Merged
merged 2 commits into from Nov 28, 2015
Merged

Call __reload hook with deletedModule #23

merged 2 commits into from Nov 28, 2015

Conversation

peteruithoven
Copy link
Contributor

Allowing one to restore state on hot reload.

Very basic usage example:

var state = [];
export function addItem(text) {
  state.push(text);
}
export function removeItem(text) {
  state = state.filter(item => item != text)
}
export function getItems() {
  return state;
}
window.addItem = addItem;
window.removeItem = removeItem;
window.getItems = getItems;

export function __reload(deletedModule){
  console.log('__reload');
  state = deletedModule.getItems();
  console.log('  restored items: ', state);
}

Allowing one to restore state on hot reload
@guybedford
Copy link
Collaborator

This looks good to me!

@capaj
Copy link
Collaborator

capaj commented Nov 28, 2015

ok, looking good here. Will write a unit test for this later.

capaj added a commit that referenced this pull request Nov 28, 2015
@capaj capaj merged commit 8f61792 into alexisvincent:master Nov 28, 2015
@peteruithoven
Copy link
Contributor Author

Usage example when using Redux; rehydrating store on reload:
https://gist.github.com/peteruithoven/59f188bfab035ce96948

@veggiemonk
Copy link

nice! Thanks for the gist!!

@johnjelinek
Copy link

@peteruithoven: the gist isn't working for me ... but also haven't figured out how to get anything to reload (regardless of state). I get console messages that file emitted change, but it doesn't cause anything to reload.

@peteruithoven
Copy link
Contributor Author

@johnjelinek Sounds like a separate issue? Please mention in that new issue where you get console messages. In the chokidar Node process or in the browser? Do you get a reimported ... statement in the browser?

@johnjelinek
Copy link

I want getting reimported messages, but I did have a changed handler off of the System.import that recognized the filename in the browser of what changed. The console messages on the server also spit out filenames of what changed.

I started a new project and it's working, I'm going to import all my modules from the old one and do a diff to see what's different between the projects.

@johnjelinek
Copy link

wasn't*, not want

@peteruithoven
Copy link
Contributor Author

@johnjelinek double check that you're importing the hot reloader. I think most people do this in their html file.

@johnjelinek
Copy link

@peteruithoven: I think my problem was actually with this: #35. The hotloader isn't being transpiled correctly by SystemJS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants