Skip to content

Commit 251a01e

Browse files
committed
fix: trigger watch func
1 parent 9197a92 commit 251a01e

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

demo/computed/behavior.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/pages/components/watch-example.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ Component({
66
a: 1,
77
sum: 1001,
88
},
9+
computed: {
10+
b(data) {
11+
return data.a
12+
}
13+
},
914
watch: {
10-
"a, behaviorTestData": function (a, behaviorTestData) {
15+
"a, behaviorTestData, b": function (a, behaviorTestData) {
16+
console.log("123")
1117
this.setData({
1218
sum: a + behaviorTestData,
1319
});

src/behavior.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export const behavior = Behavior({
171171
paths.forEach((path) => pathsMap[path.path[0]] = true);
172172
for (let computedVal in computedWatchInfo._triggerFromComputedAttached) {
173173
if (computedWatchInfo._triggerFromComputedAttached.hasOwnProperty(computedVal)) {
174-
if (pathsMap[computedVal]) {
174+
if (pathsMap[computedVal] && computedWatchInfo._triggerFromComputedAttached[computedVal]) {
175175
computedWatchInfo._triggerFromComputedAttached[computedVal] = false;
176176
return
177177
}

swc_build/behavior.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/index.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ describe("computed behavior", () => {
821821
const component = _.render(componentId);
822822
component.triggerLifeTime("attached");
823823
expect(_.match(component.dom!, "<wx-view>40</wx-view>")).toBe(true);
824-
expect(cTriggerCount).toBe(0);
824+
expect(cTriggerCount).toBe(1);
825825
expect(dTriggerCount).toBe(0);
826826

827827
})

0 commit comments

Comments
 (0)