My dilemma involves a Bacon.Bus
nested within an AMD module.
define( 'bus', [ 'bacon' ], function( Bacon ){
return new Bacon.Bus();
} );
Various modules are responsible for feeding the bus with values.
define( 'pusher', [ 'bus' ], function( bus ){
// ...
bus.push( value );
// ...
} );
Meanwhile, other modules are designed to listen for these values.
define( 'listener', [ 'bus' ], function( bus ){
bus.onValue( function( value ){
// Consume value
} );
} );
Unfortunately, any modules that are already loaded receive the pushed value, but those loaded later do not.
I attempted to address this issue by creating a Bacon.Property
to store the current value.
define( 'bus', [ 'bacon' ], function( Bacon ){
var bus = new Bacon.Bus();
bus.current = bus.toProperty();
return bus;
} );
// The pusher remains the same
define( 'listener', [ 'bus' ], function( bus ){
bus.current.onValue( function( value ){
// Consume value
} );
} );
However, this solution did not yield the desired outcome. Regardless of whether I attach `onValue` to `bus` or `bus.current`, modules loaded after the fact fail to trigger.
What am I overlooking?