0

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);

Daishi Nakajima
  • 1,932
  • 18
  • 26
  • 1
    I created this JSFiddle and the latter example code seems to work just fine: http://jsfiddle.net/opqrr02u/ – JJuutila Mar 18 '15 at 13:38
  • The error implies that `newItemView.newItemStream` is not an Observable. Have you verified it's type using dev tools? – OlliM Mar 19 '15 at 15:10
  • I tried again letter example, and it work fine. I can't reproduce the problem. I'm very sorry. Thank you very much @JJuutila . – Daishi Nakajima Mar 25 '15 at 09:06
  • @OlliM Thank you. I have verified ```newItemView.newItemStream```. It is EventStream, but it isn't instance of Observable. I've edited the question. – Daishi Nakajima Mar 25 '15 at 11:21

1 Answers1

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)

Daishi Nakajima
  • 1,932
  • 18
  • 26