Comparing version 0.0.1 to 0.0.2
61
index.js
@@ -1,60 +0,1 @@ | ||
var DependentSubscribable = require('./lib/dependent-subscribable'); | ||
var Mutable = require('./lib/mutable'); | ||
var _ = require('underscore'); | ||
var fs = require('fs'); | ||
var slice = [].slice; | ||
var computed = function() { | ||
return (new DependentSubscribable(slice.call(arguments, 0, arguments.length - 1))).computed(arguments[arguments.length - 1]); | ||
}; | ||
var fromCall = function(method, args) { | ||
return computed(function(fn) { | ||
return method.apply(null, args.concat(function(err) { | ||
if (err) { | ||
console.log(err); | ||
return; | ||
} else { | ||
fn.apply(null, slice.call(arguments, 1)); | ||
} | ||
})); | ||
}); | ||
}; | ||
_.extend(exports, { | ||
computed: computed, | ||
fromCall: fromCall, | ||
Mutable: Mutable | ||
}); | ||
var file = exports.fromCall(fs.readFile, ['./index.js', 'utf8']); | ||
var file1 = exports.fromCall(fs.readFile, ['./lib/class.js', 'utf8']); | ||
computed(file, file1, function(file, file1, callback) { | ||
callback(file + '\n' + file1); | ||
}).subscribe(function(a) { | ||
console.log(a) | ||
}); | ||
// var a = new Mutable(); | ||
// var b = new Mutable(); | ||
// a.notify(1); | ||
// b.notify(1); | ||
// var c = computed(a, 10, function(_a, _b, callback) { | ||
// callback(_a + _b); | ||
// }); | ||
// c.subscribe(function() { | ||
// console.log(arguments); | ||
// }); | ||
// a.notify(111); | ||
// b.notify(2); | ||
module.exports = process.env.RXC_COV ? require('./lib-cov/index') : require('./lib/index'); |
var PreservedSubscribable = require('./preserved-subscribable'); | ||
module.exports = PreservedSubscribable.extend({ | ||
notify: function() { | ||
if (this.isChanged.apply(this, arguments)) { | ||
module.exports = PreservedSubscribable.extend( | ||
{ | ||
value: function() { | ||
this._notify.apply(this, arguments); | ||
return this; | ||
} | ||
}, | ||
// override | ||
isChanged: function(value) { | ||
if (this._lastValue !== value) { | ||
this._lastValue = value; | ||
return true; | ||
} | ||
return false; | ||
} | ||
}); | ||
); |
@@ -0,1 +1,3 @@ | ||
var slice = [].slice; | ||
var _ = require('underscore'); | ||
var Subscribable = require('./subscribable'); | ||
@@ -5,4 +7,9 @@ var notify = Subscribable.prototype._notify; | ||
module.exports = Subscribable.extend({ | ||
var PreservedSubscribable = Subscribable.extend({ | ||
_notify: function() { | ||
if (!this._isChanged(this, arguments)) { | ||
return; | ||
} | ||
this._args = arguments; | ||
@@ -12,2 +19,21 @@ return notify.apply(this, arguments); | ||
_isChanged: function(args) { | ||
if (!this._args) { | ||
return true; | ||
} | ||
if (this._args.length !== args.length) { | ||
return true; | ||
} | ||
var self = this; | ||
return !_.all(this._args, function(arg, i) { | ||
return self.compare(arg === args[i]); | ||
}); | ||
}, | ||
compare: function(a, b) { | ||
return a === b; | ||
}, | ||
subscribe: function(fn) { | ||
@@ -18,3 +44,76 @@ if (this._args) { | ||
return subscribe.call(this, fn); | ||
}, | ||
then: function(fn) { | ||
var subscribable = new PreservedSubscribable(); | ||
this.subscribe(function() { | ||
var then = function() { | ||
mergeArray(arguments).subscribe(function(arr) { | ||
subscribable._notify.apply(subscribable, arr); | ||
}); | ||
}; | ||
var ret = fn.apply(null, slice.call(arguments).concat([then])); | ||
if (ret !== undefined) { | ||
then(ret); | ||
} | ||
}); | ||
return subscribable; | ||
} | ||
}); | ||
}); | ||
var mergeArray = function(deps) { | ||
var subscribable = new PreservedSubscribable(); | ||
var results = new Array(deps.length); | ||
var isFull = false; | ||
var check = function() { | ||
if (isFull) { | ||
notify(); | ||
return; | ||
} | ||
for (var i = 0; i < deps.length; i++) { | ||
if (!results[i]) { | ||
return; | ||
} | ||
} | ||
isFull = true; | ||
notify(); | ||
}; | ||
var notify = function() { | ||
subscribable._notify(results.reduce(function(ret, args) { | ||
ret.push.apply(ret, args); | ||
return ret; | ||
}, [])); | ||
}; | ||
_.each(deps, function(dep, i) { | ||
if (_.isArray(dep)) { | ||
dep = mergeArray(dep); | ||
} | ||
if (dep.subscribe) { | ||
dep.subscribe(function() { | ||
results[i] = slice.call(arguments); | ||
check(); | ||
}); | ||
} else { | ||
results[i] = [dep]; | ||
} | ||
}); | ||
check(); | ||
return subscribable; | ||
}; | ||
PreservedSubscribable.merge = function() { | ||
return mergeArray(arguments).then(function(arr, callback) { | ||
callback.apply(null, arr); | ||
}); | ||
}; | ||
module.exports = PreservedSubscribable; |
{ | ||
"name": "rxc", | ||
"version": "0.0.1", | ||
"author": "youngjay <hiyoungjay@gmail.com>", | ||
"description": "a reactive program tool", | ||
"keywords": [ | ||
"reactive", | ||
"async", | ||
"event" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/youngjay/rxc.git" | ||
}, | ||
"version": "0.0.2", | ||
"engine": "*", | ||
"main": "./index", | ||
"devDependencies": { | ||
"mocha": "*", | ||
"spec": "*" | ||
}, | ||
"dependencies" : { | ||
@@ -7,0 +22,0 @@ "underscore": "*" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
21866
22
631
2
2
2
2
1