ag-reactive
Advanced tools
Comparing version 1.0.26 to 1.0.27
@@ -47,3 +47,3 @@ "use strict"; | ||
var Observable_1 = require("./Observable"); | ||
var Observer_1 = require("./Observer"); | ||
var core_1 = require("./core"); | ||
var computeStack = []; | ||
@@ -66,3 +66,3 @@ function dependon(node, value) { | ||
_this.count = 0; | ||
Observer_1.dirtyNodes.add(_this); | ||
core_1.dirtyNodes.add(_this); | ||
return _this; | ||
@@ -74,3 +74,3 @@ } | ||
this.dirty = true; | ||
Observer_1.dirtyNodes.add(this); | ||
core_1.dirtyNodes.add(this); | ||
this.infoDirty(); | ||
@@ -102,3 +102,3 @@ } | ||
} | ||
Observer_1.dirtyNodes.delete(this); | ||
core_1.dirtyNodes.delete(this); | ||
this.dirty = false; | ||
@@ -131,3 +131,3 @@ this.dirties.clear(); | ||
this.dirty = false; | ||
Observer_1.dirtyNodes.delete(this); | ||
core_1.dirtyNodes.delete(this); | ||
computeStack.pop(); | ||
@@ -134,0 +134,0 @@ }; |
import { Wrapper } from "./Wrapper"; | ||
import { Delta } from "./Types"; | ||
import { Builder } from "./Builder"; | ||
export { observe, nextTick } from './core'; | ||
export declare const RawKey = "__raw"; | ||
@@ -12,6 +12,2 @@ export declare const ReactiveKey = "__reactive"; | ||
export declare function reactive<T>(raw: T, id?: string): T; | ||
export declare function observe(obj: any, cb: (delta: Delta) => void): { | ||
id: string; | ||
stop(): void; | ||
}; | ||
export declare function rebuild<T = any>(id: string): Builder<T>; |
13
index.js
@@ -31,7 +31,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.rebuild = exports.observe = exports.reactive = exports.isReactive = exports.markRaw = exports.isRaw = exports.ReactiveKey = exports.RawKey = void 0; | ||
exports.rebuild = exports.reactive = exports.isReactive = exports.markRaw = exports.isRaw = exports.ReactiveKey = exports.RawKey = exports.nextTick = exports.observe = void 0; | ||
var Wrapper_1 = require("./Wrapper"); | ||
var Observer_1 = require("./Observer"); | ||
var pretty_format_1 = __importDefault(require("pretty-format")); | ||
var Builder_1 = require("./Builder"); | ||
var core_1 = require("./core"); | ||
Object.defineProperty(exports, "observe", { enumerable: true, get: function () { return core_1.observe; } }); | ||
Object.defineProperty(exports, "nextTick", { enumerable: true, get: function () { return core_1.nextTick; } }); | ||
exports.RawKey = '__raw'; | ||
@@ -86,9 +88,2 @@ exports.ReactiveKey = '__reactive'; | ||
exports.reactive = reactive; | ||
function observe(obj, cb) { | ||
if (!isReactive(obj)) { | ||
throw 'can only observe reactive object'; | ||
} | ||
return (0, Observer_1.observe)(obj.__reactive, cb); | ||
} | ||
exports.observe = observe; | ||
function rebuild(id) { | ||
@@ -95,0 +90,0 @@ return new Builder_1.Builder(id); |
14
Obj.js
@@ -32,3 +32,3 @@ "use strict"; | ||
var Computed_1 = require("./Computed"); | ||
var Observer_1 = require("./Observer"); | ||
var core_1 = require("./core"); | ||
var Value_1 = require("./Value"); | ||
@@ -52,6 +52,6 @@ var Virtual_1 = require("./Virtual"); | ||
var e_1, _a; | ||
if (!Observer_1.dirtyProps.has(this)) { | ||
Observer_1.dirtyProps.set(this, new Set()); | ||
if (!core_1.dirtyProps.has(this)) { | ||
core_1.dirtyProps.set(this, new Set()); | ||
} | ||
var keys = Observer_1.dirtyProps.get(this); | ||
var keys = core_1.dirtyProps.get(this); | ||
if (keys.size === 0) { | ||
@@ -81,3 +81,3 @@ keys.add(key); | ||
var e_2, _a; | ||
var dirties = Observer_1.dirtyProps.get(this); | ||
var dirties = core_1.dirtyProps.get(this); | ||
if (dirties) { | ||
@@ -101,3 +101,3 @@ try { | ||
} | ||
Observer_1.dirtyProps.delete(this); | ||
core_1.dirtyProps.delete(this); | ||
} | ||
@@ -187,3 +187,3 @@ }; | ||
var snapshot = this.snapshot(); | ||
var deltas = Observer_1.globalDeltas.get(this); | ||
var deltas = core_1.globalDeltas.get(this); | ||
for (var key in deltas) { | ||
@@ -190,0 +190,0 @@ var ov = deltas[key].ov; |
@@ -48,3 +48,3 @@ "use strict"; | ||
var Reactive_1 = require("./Reactive"); | ||
var Observer_1 = require("./Observer"); | ||
var core_1 = require("./core"); | ||
var Observable = /** @class */ (function (_super) { | ||
@@ -57,7 +57,7 @@ __extends(Observable, _super); | ||
_this.inited = false; | ||
if (!Observer_1.globalDeltas.has(_this.owner)) { | ||
Observer_1.globalDeltas.set(_this.owner, {}); | ||
if (!core_1.globalDeltas.has(_this.owner)) { | ||
core_1.globalDeltas.set(_this.owner, {}); | ||
} | ||
if (!Observer_1.globalDeltas.get(_this.owner)[_this.key]) { | ||
Observer_1.globalDeltas.get(_this.owner)[_this.key] = { ov: undefined, nv: undefined }; | ||
if (!core_1.globalDeltas.get(_this.owner)[_this.key]) { | ||
core_1.globalDeltas.get(_this.owner)[_this.key] = { ov: undefined, nv: undefined }; | ||
} | ||
@@ -75,9 +75,9 @@ return _this; | ||
Observable.prototype.getdelta = function () { | ||
if (!Observer_1.globalDeltas.has(this.owner)) { | ||
Observer_1.globalDeltas.set(this.owner, {}); | ||
if (!core_1.globalDeltas.has(this.owner)) { | ||
core_1.globalDeltas.set(this.owner, {}); | ||
} | ||
if (!Observer_1.globalDeltas.get(this.owner)[this.key]) { | ||
Observer_1.globalDeltas.get(this.owner)[this.key] = { ov: this.getFormatedValue(), nv: undefined }; | ||
if (!core_1.globalDeltas.get(this.owner)[this.key]) { | ||
core_1.globalDeltas.get(this.owner)[this.key] = { ov: this.getFormatedValue(), nv: undefined }; | ||
} | ||
return Observer_1.globalDeltas.get(this.owner)[this.key]; | ||
return core_1.globalDeltas.get(this.owner)[this.key]; | ||
}; | ||
@@ -84,0 +84,0 @@ Observable.prototype.terminate = function () { |
@@ -1,14 +0,4 @@ | ||
import { Delta, KeyDelta, KeyType } from "./Types"; | ||
import { Delta } from "./Types"; | ||
import { Obj } from "./Obj"; | ||
import { Computed } from "./Computed"; | ||
export declare const globalDeltas: Map<Obj, KeyDelta>; | ||
export declare const dirtyProps: Map<Obj, Set<KeyType>>; | ||
export declare const dirtyNodes: Set<Computed>; | ||
export declare function observe(target: Obj, cb: (delta: Delta) => void): { | ||
id: string; | ||
stop(): void; | ||
}; | ||
export declare class Observer { | ||
readonly target: Obj; | ||
constructor(target: Obj); | ||
update: Set<Obj>; | ||
@@ -15,0 +5,0 @@ addRemove: Map<Obj, [boolean, boolean]>; |
110
Observer.js
@@ -30,100 +30,12 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Observer = exports.observe = exports.dirtyNodes = exports.dirtyProps = exports.globalDeltas = void 0; | ||
var updatedObservers = new Set(); | ||
exports.globalDeltas = new Map(); | ||
exports.dirtyProps = new Map(); | ||
exports.dirtyNodes = new Set(); | ||
var tobeCleaned = new Set(); | ||
function sweep() { | ||
var e_1, _a, e_2, _b, e_3, _c, e_4, _d; | ||
var ret = []; | ||
try { | ||
for (var dirtyNodes_1 = __values(exports.dirtyNodes), dirtyNodes_1_1 = dirtyNodes_1.next(); !dirtyNodes_1_1.done; dirtyNodes_1_1 = dirtyNodes_1.next()) { | ||
var node = dirtyNodes_1_1.value; | ||
node.backTraceDirtyPath(); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (dirtyNodes_1_1 && !dirtyNodes_1_1.done && (_a = dirtyNodes_1.return)) _a.call(dirtyNodes_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
exports.dirtyNodes.clear(); | ||
try { | ||
for (var tobeCleaned_1 = __values(tobeCleaned), tobeCleaned_1_1 = tobeCleaned_1.next(); !tobeCleaned_1_1.done; tobeCleaned_1_1 = tobeCleaned_1.next()) { | ||
var obj = tobeCleaned_1_1.value; | ||
obj.forwardClearDirty(); | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (tobeCleaned_1_1 && !tobeCleaned_1_1.done && (_b = tobeCleaned_1.return)) _b.call(tobeCleaned_1); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
try { | ||
for (var updatedObservers_1 = __values(updatedObservers), updatedObservers_1_1 = updatedObservers_1.next(); !updatedObservers_1_1.done; updatedObservers_1_1 = updatedObservers_1.next()) { | ||
var observer = updatedObservers_1_1.value; | ||
var delta = observer.getDeltas(); | ||
if (Object.keys(delta).length > 0) { | ||
ret.push([observer, delta]); | ||
} | ||
} | ||
} | ||
catch (e_3_1) { e_3 = { error: e_3_1 }; } | ||
finally { | ||
try { | ||
if (updatedObservers_1_1 && !updatedObservers_1_1.done && (_c = updatedObservers_1.return)) _c.call(updatedObservers_1); | ||
} | ||
finally { if (e_3) throw e_3.error; } | ||
} | ||
updatedObservers.clear(); | ||
exports.globalDeltas.clear(); | ||
try { | ||
for (var ret_1 = __values(ret), ret_1_1 = ret_1.next(); !ret_1_1.done; ret_1_1 = ret_1.next()) { | ||
var _e = __read(ret_1_1.value, 2), observer = _e[0], delta = _e[1]; | ||
var cb = callbacks.get(observer); | ||
cb(delta); | ||
} | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
try { | ||
if (ret_1_1 && !ret_1_1.done && (_d = ret_1.return)) _d.call(ret_1); | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
} | ||
setInterval(sweep, 0); | ||
var callbacks = new Map(); | ||
function observe(target, cb) { | ||
var observer = new Observer(target); | ||
callbacks.set(observer, cb); | ||
return { | ||
id: target.id, | ||
stop: function () { | ||
target.wilter(observer, observer, []); | ||
callbacks.delete(observer); | ||
} | ||
}; | ||
} | ||
exports.observe = observe; | ||
exports.Observer = void 0; | ||
var core_1 = require("./core"); | ||
var Observer = /** @class */ (function () { | ||
function Observer(target) { | ||
this.target = target; | ||
function Observer() { | ||
this.update = new Set(); | ||
this.addRemove = new Map(); | ||
var fakeProp = { | ||
backTraceDirtyPath: function () { | ||
tobeCleaned.add(target); | ||
} | ||
}; | ||
this.target.grow(this, fakeProp); | ||
} | ||
Observer.prototype.markUpdate = function (observable) { | ||
this.update.add(observable); | ||
updatedObservers.add(this); | ||
core_1.updatedObservers.add(this); | ||
}; | ||
@@ -140,6 +52,6 @@ Observer.prototype.updateObjState = function (obj, nv) { | ||
} | ||
updatedObservers.add(this); | ||
core_1.updatedObservers.add(this); | ||
}; | ||
Observer.prototype.getDeltas = function () { | ||
var e_5, _a, e_6, _b; | ||
var e_1, _a, e_2, _b; | ||
var ret = {}; | ||
@@ -166,3 +78,3 @@ try { | ||
} | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
@@ -172,3 +84,3 @@ try { | ||
} | ||
finally { if (e_5) throw e_5.error; } | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
@@ -178,3 +90,3 @@ try { | ||
var observable = _h.value; | ||
var delta = exports.globalDeltas.get(observable); | ||
var delta = core_1.globalDeltas.get(observable); | ||
if (delta && Object.keys(delta).length > 0) { | ||
@@ -188,3 +100,3 @@ ret[observable.id] = { | ||
} | ||
catch (e_6_1) { e_6 = { error: e_6_1 }; } | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
@@ -194,3 +106,3 @@ try { | ||
} | ||
finally { if (e_6) throw e_6.error; } | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
@@ -197,0 +109,0 @@ this.addRemove.clear(); |
{ | ||
"name": "ag-reactive", | ||
"version": "1.0.26", | ||
"version": "1.0.27", | ||
"description": "", | ||
@@ -11,3 +11,2 @@ "author": "", | ||
"dependencies": { | ||
"consola": "^3.2.3", | ||
"pretty-format": "^29.7.0" | ||
@@ -14,0 +13,0 @@ }, |
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
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
61698
1
25
1654
- Removedconsola@^3.2.3
- Removedconsola@3.3.3(transitive)