I have a Bacon.Bus
within an AMD module.
define( 'bus', [ 'bacon' ], function( Bacon ){
return new Bacon.Bus();
} );
Other modules push values onto the bus.
define( 'pusher', [ 'bus' ], function( bus ){
// ...
bus.push( value );
// ...
} );
While other modules listen for values.
define( 'listener', [ 'bus' ], function( bus ){
bus.onValue( function( value ){
// Consume value
} );
} );
Any modules that are currently loaded receive the pushed value; however any modules loaded afterwards do not.
I tried creating a Bacon.Property
to hold the current value.
define( 'bus', [ 'bacon' ], function( Bacon ){
var bus = new Bacon.Bus();
bus.current = bus.toProperty();
return bus;
} );
// The pusher is unchanged
define( 'listener', [ 'bus' ], function( bus ){
bus.current.onValue( function( value ){
// Consume value
} );
} );
This still did not solve the problem though. Whether I attach onValue
to bus
or bus.current
, modules loaded after the fact do not get triggered.
What am I missing?
This is practically the same old laziness issue: https://github.com/baconjs/bacon.js/wiki/FAQ#why-isnt-my-property-updated
As a workaround, you can add a no-op subscriber to the property to make sure it gets updated even when there are no actual subscribers. Or you can use https://github.com/baconjs/bacon.model