cycle-restart
cycle-restart copied to clipboard
Usage with systemjs-hot-reloader
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?
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.
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?
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.
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