forked from mikeric/rivets
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add computed properties doc and example
- Loading branch information
Showing
3 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Computed properties are re-evaluated when one or more dependent properties change. Declaring computed properties in Tinybind.js is possible by using buitin `watch` formatter followed by its dependencies. The following text binding will get re-evaluated when either the event's `start` or `end` attribute changes. | ||
|
||
```html | ||
<span rv-text="dateRange | watch start end"></span> | ||
``` |
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,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<script src="../dist/tinybind.js"></script> | ||
|
||
<title>Computed</title> | ||
</head> | ||
|
||
<body> | ||
<h2>Computed properties</h2> | ||
<div id="test"> | ||
<button rv-on-click="incStart">Inc start</button> | ||
<button rv-on-click="incEnd">Inc end</button> | ||
|
||
<span rv-text="dateRange | watch start end"></span> | ||
</div> | ||
|
||
|
||
<script> | ||
var model = { | ||
start: 1, | ||
end: 2, | ||
get dateRange() { | ||
return 'From ' + this.start + ' to ' + this.end | ||
}, | ||
incStart() { | ||
model.start++ | ||
}, | ||
incEnd() { | ||
model.end++ | ||
} | ||
} | ||
tinybind.bind(document.getElementById("test"), model); | ||
</script> | ||
</body> | ||
|
||
</html> |