watcher.md 951 B

Watcher pattern - eventual

Case Loader wants to know if modules were installed by installer

Events will not work because of order: ex

  1. Installer starts,
  2. Install modules,
  3. and emit "installed" event

  4. loader listens for installed event ---------- This will never get called since event was emited before

  5. then load modules

Solution:

 	// hci-loader
	// This will be fired right away with undefined if there is no value setted
	loader_context.watch('hci-installer:installed',(value) => {
		if(value == true) {
			this.loadBundles();
		}
	});

	// hci-installer
	// This will store value in a contextual property and fire event for 'hci-installer:installed'
	installer_context.value('installed',true); // Not that will send 'modname':context

It can be used for several other things, storing states, listening for things, event alternative events

  • values should be stored within context?
  • watchers same: