cycle-restart icon indicating copy to clipboard operation
cycle-restart copied to clipboard

Usage with systemjs-hot-reloader

Open OliverJAsh opened this issue 9 years ago • 4 comments

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 https://github.com/capaj/systemjs-hot-reloader/pull/23#issue-119311376

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

OliverJAsh avatar Feb 07 '16 19:02 OliverJAsh

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.

djindjic avatar Feb 25 '16 08:02 djindjic

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?

Widdershin avatar Feb 25 '16 08:02 Widdershin

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.

guybedford avatar Feb 25 '16 12:02 guybedford

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

Widdershin avatar Feb 25 '16 20:02 Widdershin