forked from sveltejs/svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request sveltejs#416 from sveltejs/sveltejsgh-413
recompute computed values with functions as dependencies
- Loading branch information
Showing
4 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/generator/samples/computed-values-function-dependency/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
html: '<p>2</p>', | ||
|
||
test ( assert, component, target ) { | ||
component.set({ y: 2 }); | ||
assert.equal( component.get( 'x' ), 4 ); | ||
assert.equal( target.innerHTML, '<p>4</p>' ); | ||
component.destroy(); | ||
} | ||
}; |
28 changes: 28 additions & 0 deletions
28
test/generator/samples/computed-values-function-dependency/main.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<p>{{x}}</p> | ||
|
||
<script> | ||
let _x; | ||
|
||
function getX () { | ||
return _x; | ||
} | ||
|
||
export default { | ||
data () { | ||
return { | ||
y: 1 | ||
}; | ||
}, | ||
|
||
computed: { | ||
xGetter ( y ) { | ||
_x = y * 2; | ||
return getX; | ||
}, | ||
|
||
x ( xGetter ) { | ||
return xGetter(); | ||
} | ||
} | ||
}; | ||
</script> |