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

Usage with systemjs-hot-reloader #33

Open
OliverJAsh opened this issue Feb 7, 2016 · 4 comments
Open

Usage with systemjs-hot-reloader #33

OliverJAsh opened this issue Feb 7, 2016 · 4 comments

Comments

@OliverJAsh
Copy link

systemjs-hot-reloader provides a __reload hook for each module, which can be used like so:

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);
}

Example taken from alexisvincent/systemjs-hot-reloader#23 (comment)

Do you have any ideas how to make cycle-restart work given this model?

@djindjic
Copy link

Hi @Widdershin, @OliverJAsh. I'm also interested for this feature, but don't have enough knowledge to handle it. Maybe @capaj and @guybedford could help? I think there is interest on all sides because jspm gives us very good support of combining different plugins and cyclejs is probablly on top of front end patterns at this moment.

@Widdershin
Copy link
Owner

The idea is that you should have a module that exports your main function, and that when that code (or any of the code that main depends upon) changes, a hook should be called that then calls restart with the new code.

Does that fit into the model systemjs provides?

@guybedford
Copy link

It sounds like the __reload hook above in the main module would do it, as it runs if any of the dependencies of that module are updated. It may be worth verifying with @capaj though that reload is run for every parent module, as that was a missing feature last I checked.

@Widdershin
Copy link
Owner

It would be awesome if someone with some system js experience could take a crack at getting an example running. I'm happy to provide support if any problems pop up

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

No branches or pull requests

4 participants