bacon.js Bus.plug: Uncaught Error: not an Observable : [object Object]

这一生的挚爱 提交于 2020-01-06 14:08:11

问题


I was trying baconjs's tutorial. https://baconjs.github.io/tutorials.html#content/tutorials/2_Ajax

But, I got the error at "Bus.plug"

var cart = ShoppingCarEt([])
var cartView = ShoppingCartView(cart.contentsProperty)
var newItemView = NewItemView()
cart.addBus.plug(newItemView.newItemStream)

Error:

Uncaught Error: not an Observable : [object Object]
shopBundle.js:145 assertObservable
shopBundle.js:2650 Bus.plug

I use follows

  • baconjs@0.7.53
  • jquery@2.1.3
  • bacon-jquery-bindings@0.2.8
  • webpack 1.7.3

What am I doing wrong? Thanks.


Edit: 2015/3/25

Cause is that newItemView.newItemStream is not Observable.
(newItemView.newItemStream instanceof Bacon.Observable returns false.)

And newItemView.newItemStream is EventStream

EventStream {takeUntil: function, sampledBy: function, combine: function, flatMapLatest: function, fold: function…}

Isn't all EventStream an Observable?

I have made newItemStream as follows:

var $button = $('#addButton');
var $nameField = $('#nameText');
var newItemProperty = Bacon.$.textFieldValue($nameField);
var newItemClick = $button.asEventStream('click');
var newItemStream = newItemProperty.sampledBy(newItemClick);

Following is work fine. It was my miss when first time question.

/* And, I try more simple code. It has same error. */

 var someStream = Bacon.interval(1000).map(function() {
    return new Date().getTime();
});
var bus = new Bacon.Bus();
bus.log();
bus.plug(someStream);


回答1:


It 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 asEventStream function.

We should use "bacon.jquery"(https://www.npmjs.com/package/bacon.jquery)



来源:https://stackoverflow.com/questions/29090514/bacon-js-bus-plug-uncaught-error-not-an-observable-object-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!