Skip to content

Commit

Permalink
Merge pull request #12 from canjs/major
Browse files Browse the repository at this point in the history
4.0
  • Loading branch information
matthewp authored Jan 29, 2018
2 parents 76c13c9 + 707cd0e commit f619b7d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
12 changes: 6 additions & 6 deletions can-stream.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var namespace = require('can-util/namespace');
var compute = require('can-compute');
var makeArray = require('can-util/js/make-array/make-array');
var assign = require("can-util/js/assign/assign");
var assign = require("can-assign");
var compute = require("can-compute");
var canReflect = require("can-reflect");
var namespace = require("can-namespace");

var toComputeFromEvent = function(observable, eventName){
var handler,
Expand All @@ -11,7 +11,7 @@ var toComputeFromEvent = function(observable, eventName){
handler = function(ev, val) {
lastSet = assign({
args: [].slice.call(arguments, 1)
},ev);
}, ev);
updated();
};
observable.on(eventName, handler);
Expand Down Expand Up @@ -121,7 +121,7 @@ var STREAM = function(canStreamInterface) {
};

var toCompute = function(makeStream, context) {
var args = makeArray(arguments);
var args = canReflect.toArray(arguments);
return canStreamInterface.toCompute.apply(this, args);
};

Expand Down
36 changes: 18 additions & 18 deletions can-stream_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ test('Compute changes can be streamed', function () {
QUnit.equal(computeVal, 3);
});

test('Compute streams do not bind to the compute unless activated', function () {
QUnit.test('Compute streams do not bind to the compute unless activated', function(assert) {
var c = compute(0);

var canStreamInterface = {
toStream: function(observable, propOrEvent) {
QUnit.equal(c, observable);
var obj;
return obj = {
assert.equal(c, observable);
return {
onValue: function(callback) {
c.on('change', function(evnt, newVal, oldVal) {
callback(newVal);
Expand All @@ -91,17 +91,16 @@ test('Compute streams do not bind to the compute unless activated', function ()
},
toCompute: function(makeStream, context) {}
};

var canStreaming = canStream(canStreamInterface);
var stream = canStreaming.toStream(c);

QUnit.equal(c.computeInstance.__bindEvents, undefined);
assert.notOk(c.computeInstance.bound, "should not be bound");

stream.onValue(function () {});

QUnit.equal(c.computeInstance.__bindEvents._lifecycleBindings, 1);
stream.onValue(function() {});
assert.ok(c.computeInstance.bound, "should be bound");
});


test('Stream on a property val - toStreamFromEvent', function(){
var expected = "bar";
var MyMap = DefineMap.extend({
Expand Down Expand Up @@ -169,8 +168,7 @@ test('Stream on a property val - toStreamFromProperty', function(){

});


test('Event streams fire change events', function () {
QUnit.test('Event streams fire change events', function(assert) {
var expected = 0;
var MyMap = DefineMap.extend({
fooList: {
Expand All @@ -194,20 +192,22 @@ test('Event streams fire change events', function () {
var canStreaming = canStream(canStreamInterface);

var map = new MyMap();

var stream = canStreaming.toStream(map.fooList, 'length');

stream.onValue(function(lengthEvent){
QUnit.equal(lengthEvent.type, "length");
QUnit.deepEqual(lengthEvent.args, expected, 'Event stream was updated with length: ' + map.fooList.length);
stream.onValue(function(lengthEvent) {
assert.equal(lengthEvent.type, "length");
assert.deepEqual(
lengthEvent.args,
expected,
'Event stream was updated with length: ' + map.fooList.length
);
});

expected = [1];
expected = [1, 0]; // [newValue, oldValue]
map.fooList.push(1);

expected = [0];
expected = [0, 1]; // [newValue, oldValue]
map.fooList.pop();

});

test('Event streams fire change event on a property', function () {
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "can-stream",
"version": "0.3.2",
"version": "1.0.0-pre.0",
"description": "Stream values into and out of computes",
"homepage": "http://canjs.com",
"author": {
Expand Down Expand Up @@ -35,13 +35,14 @@
]
},
"dependencies": {
"can-compute": "^3.2.0",
"can-define": "^1.2.0",
"can-event": "^3.5.0",
"can-observation": "^3.2.0",
"can-assign": "^1.1.1",
"can-compute": "^4.0.0",
"can-define": "^2.0.0",
"can-namespace": "^1.0.0",
"can-observation": "^4.0.0",
"can-reflect": "^1.11.0",
"can-types": "^1.1.0",
"can-util": "^3.9.0",
"kefir": "^3.5.1"
"kefir": "^3.8.0"
},
"devDependencies": {
"bit-docs": "0.0.7",
Expand Down

0 comments on commit f619b7d

Please sign in to comment.