Skip to content

Commit

Permalink
fix: fix getter logic
Browse files Browse the repository at this point in the history
  • Loading branch information
qddegtya committed Jan 30, 2021
1 parent 5b57f05 commit 82588c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions __future__/trp.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ const TR = (o) => {
binds = [],
preOldVal = null,
preNewVal = null,
latestVal = null
latestVal = _o

return {
bind(r) {
binds.push(r)
},

get() {
return _o
return latestVal
},

observe(cb) {
Expand All @@ -35,6 +35,7 @@ const TR = (o) => {
preNewVal = newVal

// 深度优先
// TODO: 拓扑执行
if (binds.length > 0) {
binds.forEach((r) => r.change())
}
Expand Down
5 changes: 3 additions & 2 deletions dist/ajs.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,14 @@ var TR = function TR(o) {
binds = [],
preOldVal = null,
preNewVal = null,
latestVal = null;
latestVal = _o;

return {
bind: function bind(r) {
binds.push(r);
},
get: function get() {
return _o;
return latestVal;
},
observe: function observe(cb) {
notify = cb;
Expand All @@ -875,6 +875,7 @@ var TR = function TR(o) {
if (preOldVal === oldVal && preNewVal === newVal) return;
preOldVal = oldVal;
preNewVal = newVal; // 深度优先
// TODO: 拓扑执行

if (binds.length > 0) {
binds.forEach(function (r) {
Expand Down
4 changes: 4 additions & 0 deletions test/trp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ setTimeout(() => {
});
}, 1000);

console.log("before: ", count2.get());

count2.change(() => 6);

console.log("after: ", count2.get());

0 comments on commit 82588c1

Please sign in to comment.