mobservable
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,2 @@ | ||
/// <reference path="./typings/node-0.10.d.ts" /> | ||
var __extends = this.__extends || function (d, b) { | ||
@@ -7,3 +8,7 @@ for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
}; | ||
/// <reference path="./typings/node-0.10.d.ts" /> | ||
/** | ||
* MOBservable | ||
* (c) 2015 - Michel Weststrate | ||
* https://github.com/mweststrate/mobservable | ||
*/ | ||
var events = require('events'); | ||
@@ -26,2 +31,18 @@ function property(value, scope) { | ||
exports.property = property; | ||
function guard(func, onInvalidate) { | ||
var dnode = new DNode(); | ||
var retVal; | ||
dnode.compute = function (done) { | ||
retVal = func(); | ||
dnode.compute = function (done2) { | ||
done2(); | ||
dnode.dispose(); | ||
onInvalidate(); | ||
}; | ||
done(); | ||
}; | ||
dnode.computeNextValue(); | ||
return [retVal, function () { return dnode.dispose(); }]; | ||
} | ||
exports.guard = guard; | ||
function batch(action) { | ||
@@ -226,2 +247,8 @@ Scheduler.batch(action); | ||
}; | ||
DNode.prototype.dispose = function () { | ||
var _this = this; | ||
this.observing.forEach(function (observing) { return observing.removeObserver(_this); }); | ||
this.observing = []; | ||
// Do something with the observers, notify some state like KILLED? | ||
}; | ||
/* | ||
@@ -228,0 +255,0 @@ Dependency detection |
/// <reference path="./typings/node-0.10.d.ts" /> | ||
/** | ||
* MOBservable | ||
* (c) 2015 - Michel Weststrate | ||
* https://github.com/mweststrate/mobservable | ||
*/ | ||
import events = require('events'); | ||
@@ -33,2 +40,18 @@ | ||
export function guard<T>(func:()=>T, onInvalidate:Lambda):[T,Lambda] { | ||
var dnode = new DNode(); | ||
var retVal:T; | ||
dnode.compute = function(done) { | ||
retVal = func(); | ||
dnode.compute = function(done2) { | ||
done2(); | ||
dnode.dispose(); | ||
onInvalidate(); | ||
} | ||
done(); | ||
} | ||
dnode.computeNextValue(); | ||
return [retVal, () => dnode.dispose()]; | ||
} | ||
export function batch(action:Lambda) { | ||
@@ -260,2 +283,8 @@ Scheduler.batch(action); | ||
} | ||
public dispose() { | ||
this.observing.forEach(observing => observing.removeObserver(this)); | ||
this.observing = []; | ||
// Do something with the observers, notify some state like KILLED? | ||
} | ||
} | ||
@@ -262,0 +291,0 @@ |
{ | ||
"name": "mobservable", | ||
"version": "0.0.1", | ||
"description": "Changes are coming! Small library for creating observable properties en functions", | ||
"main": "mobservable.js", | ||
"scripts": { | ||
"test": "node_modules/.bin/nodeunit test/", | ||
"prepublish": "node_modules/typescript-require/node_modules/typescript/bin/tsc -m commonjs -t ES5 mobservable.ts" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mweststrate/mobservable.git" | ||
}, | ||
"author": "Michel Weststrate", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/mweststrate/mobservable/issues" | ||
}, | ||
"homepage": "https://github.com/mweststrate/mobservable", | ||
"devDependencies": { | ||
"nodeunit": "^0.9.1", | ||
"typescript-require": "^0.2.8" | ||
} | ||
} | ||
"name": "mobservable", | ||
"version": "0.0.2", | ||
"description": "Changes are coming! Small library for creating observable properties en functions", | ||
"main": "mobservable.js", | ||
"scripts": { | ||
"test": "node_modules/.bin/nodeunit test/", | ||
"prepublish": "node_modules/typescript-require/node_modules/typescript/bin/tsc -m commonjs -t ES5 mobservable.ts" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mweststrate/mobservable.git" | ||
}, | ||
"author": "Michel Weststrate", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/mweststrate/mobservable/issues" | ||
}, | ||
"homepage": "https://github.com/mweststrate/mobservable", | ||
"devDependencies": { | ||
"nodeunit": "^0.9.1", | ||
"nscript": "^0.1.5", | ||
"typescript-require": "^0.2.8" | ||
} | ||
} |
@@ -70,2 +70,10 @@ # MOBservable | ||
### mobservable.guard(func, onInvalidate) | ||
`guard` invokes `func` and returns a tuple consisting of the return value of `func` and an unsubscriber. `guard` will track which observables `func` was observing, but it will *not* recalculate `func` if necessary, instead, it will fire the `onInvalidate` callback to notify that the output of `func` can no longer be trusted. | ||
The `onInvalidate` function will be called only once, after that, the guard has finished. To abort a guard, use the returned unsubscriber. | ||
Guard is useful in functions where you want to have `func` observable, but func is actually invoked as side effect or part of a bigger change flow or where unnecessary recalculations of `func` or either pointless or expensive. | ||
### mobservable.batch(workerFunction) | ||
@@ -72,0 +80,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101
24431
3
5
607
1