Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chasenlehara committed Jul 5, 2018
1 parent fb52502 commit 526c521
Show file tree
Hide file tree
Showing 2 changed files with 8,263 additions and 0 deletions.
83 changes: 83 additions & 0 deletions dist/amd/can-stream-kefir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*can-stream-kefir@1.1.0#can-stream-kefir*/
define([
'require',
'exports',
'module',
'can-kefir',
'can-compute',
'can-stream',
'can-symbol',
'can-namespace'
], function (require, exports, module) {
'use strict';
var Kefir = require('can-kefir');
var compute = require('can-compute');
var canStream = require('can-stream');
var canSymbol = require('can-symbol');
var namespace = require('can-namespace');
var getValueDependenciesSymbol = canSymbol.for('can.getValueDependencies');
var getKeyDependenciesSymbol = canSymbol.for('can.getKeyDependencies');
var canStreamKefir = {};
canStreamKefir.toStream = function (compute) {
var stream = Kefir.stream(function (emitter) {
var changeHandler = function (ev, newVal) {
emitter.emit(newVal);
};
compute.on('change', changeHandler);
var currentValue = compute();
if (currentValue !== undefined) {
emitter.emit(currentValue);
}
return function () {
compute.off('change', changeHandler);
};
});
stream[getValueDependenciesSymbol] = function getValueDependencies() {
return { valueDependencies: new Set([compute]) };
};
return stream;
};
canStreamKefir.toCompute = function (makeStream, context) {
var emitter, lastValue, streamHandler, lastSetValue;
var setterStream = Kefir.stream(function (e) {
emitter = e;
if (lastSetValue !== undefined) {
emitter.emit(lastSetValue);
}
});
var valueStream = makeStream.call(context, setterStream);
var streamCompute = compute(undefined, {
get: function () {
return lastValue;
},
set: function (val) {
if (emitter) {
emitter.emit(val);
} else {
lastSetValue = val;
}
return val;
},
on: function (updated) {
streamHandler = function (val) {
lastValue = val;
updated();
};
valueStream.onValue(streamHandler);
},
off: function () {
valueStream.offValue(streamHandler);
}
});
var _compute = streamCompute.computeInstance;
_compute[getKeyDependenciesSymbol] = function getKeyDependencies(key) {
if (key === 'change') {
return { valueDependencies: new Set([valueStream]) };
}
};
return streamCompute;
};
if (!namespace.streamKefir) {
module.exports = namespace.streamKefir = canStream(canStreamKefir);
}
});
Loading

0 comments on commit 526c521

Please sign in to comment.