Bacon.js Bus.plug: error with impure: not observable: [object Object]
I tried to learn baconjs. https://baconjs.github.io/tutorials.html#content/tutorials/2_Ajax
But, I got an error in "Bus.plug"
var cart = ShoppingCarEt([])
var cartView = ShoppingCartView(cart.contentsProperty)
var newItemView = NewItemView()
cart.addBus.plug(newItemView.newItemStream)
Mistake:
Uncaught Error: not an Observable : [object Object]
shopBundle.js:145 assertObservable
shopBundle.js:2650 Bus.plug
I am using the following
- baconjs@0.7.53
- jquery@2.1.3
- bacon-jquery-bindings@0.2.8
- webpack 1.7.3
What am I doing wrong? Thank.
Edit: 2015/3/25
The reason is that newItemView.newItemStream is not being observed.
( newItemView.newItemStream instanceof Bacon.Observable
returns false.)
And newItemView.newItemStream is EventStream
EventStream {takeUntil: function, sampledBy: function, combine: function, flatMapLatest: function, fold: function…}
Are not all monitored events EventStream?
I made a newItemStream like this:
var $button = $('#addButton');
var $nameField = $('#nameText');
var newItemProperty = Bacon.$.textFieldValue($nameField);
var newItemClick = $button.asEventStream('click');
var newItemStream = newItemProperty.sampledBy(newItemClick);
The following works great. It was my mistake on the first question.
/ * And I try simpler code. He has the same error. * /
var someStream = Bacon.interval(1000).map(function() {
return new Date().getTime();
});
var bus = new Bacon.Bus();
bus.log();
bus.plug(someStream);
source to share
This was caused by "bacon-jquery-bindings" ( https://www.npmjs.com/package/bacon-jquery-bindings )
var Bacon = require('baconjs');
var $ = jQuery = require("jquery");
Bacon.$ = require("bacon-jquery-bindings"); <-
It seems to overwrite the asEventStream function.
We should use "bacon.jquery" ( https://www.npmjs.com/package/bacon.jquery )
source to share