Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dstream

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dstream - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

bower.json

150

dstream.js

@@ -15,10 +15,5 @@ // Chapter 0 - Internal utilities

function isArray(object) {
// TODO compatibility
return Array.isArray(object);
}
function isStream(object) {
return object instanceof Stream;
}
// Testing utils (in test environment, these exist and do what they say)

@@ -39,2 +34,4 @@ if (typeof test !== 'function') {

// defer(f) - call 'f' a bit later
var defer = typeof setImmediate === 'function' ? setImmediate : setTimeout;

@@ -278,2 +275,4 @@ // Chapter 1 - Stream() and stream()

this.addEndListener(f);
// return something?
};

@@ -395,3 +394,4 @@

// Chapter 2 - Stream utilities.
// Chapter X - Stream utilities
//
// Functions that create new streams or help creating them.

@@ -415,2 +415,4 @@

// Make a stream from a promise.
// TODO should probably be either stream(promise) or stream.from(promise)
// Maybe the former -- streams and promises should be interchangeable
stream.fromPromise = function(promise) {

@@ -428,41 +430,2 @@ var result = stream();

stream.fromCallback = function(f) {
assert(typeof f === 'function');
assert(arguments.length <= 1);
var result = stream();
f(function(value) {
result.set(value);
});
return result;
};
stream.fromNodeCallback = function(f) {
assert(typeof f === 'function');
assert(arguments.length <= 1);
var result = stream();
f(function(err, value) {
assert(!err);
result.set(value);
});
return result;
};
// TODO replace with .sample()
stream.fromPoll = function(interval, f) {
var result = stream();
setInterval(function() {
result.set(f());
}, interval);
return result;
};
var defer = typeof setImmediate === 'function' ? setImmediate : setTimeout;
// Produce a stream that yields the elements of array as fast as it can.

@@ -487,14 +450,3 @@ stream.fromArray = function(array) {

stream.fromBinder = function(f) {
var result = stream();
function sink(value) {
result.set(value);
}
f(sink);
return result;
};
// TODO decide the fate of these
stream.interval = function(interval, value) {

@@ -535,6 +487,2 @@ return stream.repeatedly(interval, [value]);

stream.never = function() {
return stream();
};
stream.later = function(delay, value) {

@@ -550,9 +498,11 @@ var result = stream();

// TODO bacon compatibility: new Bacon.EventStream(subscribe)
// Chapter 4 - Stream.set() and its internal mechanisms
// stream.updateOrder(Stream source) -> Stream[]
//
// Given that the value of 'source' is set, which streams should we consider
// updating and in which order?
//
// I.e. a topological ordering of streams reachable from 'source' through parent-child
// relationships.
// Returns a topological ordering of streams reachable from 'source' through
// parent-child relationships.
//

@@ -581,3 +531,3 @@ // var s = stream();

//
// from which we will pick the last occurrence of each node:
// from which we will pick only the last occurrence of each node:
//

@@ -604,3 +554,3 @@ // result = [ 1, 2, 3, 4 ]

//
// Return 'this' so you can do s.set(1).set(2)... or whatever.
// Return 'this' so you can do things like s.set(1).forEach(f).
Stream.prototype.set = function(value) {

@@ -659,6 +609,6 @@ stream.version++;

// Chapter 3. Stream operators
// Chapter 3 - Stream operators
// Create a stream that depends on this stream, install an update handler
// on it and calls it if this stream has a value. This should be used
// on it and call it if this stream has a value. This should be used
// by most stream operators that take a single parent stream, such as

@@ -859,5 +809,17 @@ // map, filter, uniq, etc.

// Stream.log(optional String prefix) -> Stream
//
// For each value given by the stream, print it out using console.log,
// with 'prefix' as the first argument if provided.
//
// Return the stream itself for chainability.
//
// stream.set(1).log().set(2);
// // -> 1; 2
//
// stream.set(1).log('value');
// // -> value 1
//
Stream.prototype.log = function(prefix) {
this.onValue(function(value) {
this.forEach(function(value) {
if (prefix) {

@@ -872,3 +834,16 @@ console.log(prefix, value);

Stream.prototype.merge = function(other) {
// Chapter X - stream combinators
// stream.merge(Stream s1, Stream s2) -> Stream - merge 's1' and 's2'
//
// var result = stream.merge(s1, s2)
// s1 1 2 5 6
// s2 1 2 6
// result 1 1 2 2 5 6 6
//
// If any of the argument streams change their value simultaneously,
// the last one takes effect.
//
// TODO generalize
stream.merge = function(s1, s2) {
function mergeUpdate(parent1, parent2) {

@@ -884,23 +859,20 @@ if (parent1.wasChanged()) {

return stream({
parents: [ this, other ],
update: mergeUpdate
});
return stream([ s1, s2 ], mergeUpdate);
};
// TODO make this work on a stream that already has value
// like bacon's property scan already does
// TODO make this work without an initial value
// TODO and the previous cases combined
// like .reduce() would work, presumably.
// Like in the previous stream library incarnation, if I recall correctly
Stream.prototype.scan = function(initial, f) {
return stream({
parents: [ this ],
update: function scanUpdate(parent) {
// Stream.reduce(Function f, optional Object initial) -> Stream
//
// Reduce a stream. Like Array.reduce(), except that the resulting stream
// also shows the intermediate values of the process.
//
Stream.prototype.reduce = function(f, initial) {
function reduceUpdate(parent) {
if (this.hasValue()) {
this.newValue(this.f(this.value, parent.value));
},
value: initial,
f: f
});
} else {
this.newValue(parent.value);
}
}
return stream(this, reduceUpdate, { value: initial, f: f });
};

@@ -907,0 +879,0 @@

{
"name": "dstream",
"version": "0.0.1",
"version": "0.0.2",
"description": "Downstream",

@@ -14,3 +14,3 @@ "main": "dstream.js",

"type": "git",
"url": "git://github.com/anttisykari/dstream.git"
"url": "git://github.com/anttisykari/downstream.git"
},

@@ -26,5 +26,8 @@ "keywords": [

"bugs": {
"url": "https://github.com/anttisykari/dstream/issues"
"url": "https://github.com/anttisykari/downstream/issues"
},
"homepage": "https://github.com/anttisykari/dstream"
"homepage": "https://github.com/anttisykari/downstream",
"devDependencies": {
"bower": "^1.3.12"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc