Skip to content

Commit

Permalink
better examples
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Feb 12, 2017
1 parent 3f3429a commit eaefddd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
5 changes: 2 additions & 3 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
h1 { font-size: 1.2em; }
input { display: block; margin: 8px auto; }
</style>
<script>window.Promise||document.write('<script src="js-browser/promise-pjs.js"><'+'/script>')</script>
<script>process={browser:true}</script>
<script defer src="../wrist.min.js"></script>
</head>
<body><h1>wrist.js examples</h1></body>
<script defer id="common-js" data-main="./main.js" src="https://unpkg.com/common-js@0.3.5/common.js"></script>
<script defer src="main.js"></script>
</html>
12 changes: 5 additions & 7 deletions examples/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var wrist = require('../wrist');

var input1 = document.body.appendChild(
document.createElement('input')
);
Expand All @@ -17,20 +15,20 @@ function changeValue2(prop, prev, curr) {
}

function changeGlobalTest(prop, prev, curr) {
global.test[prop] = curr;
window.test[prop] = curr;
}

global.test = {};
window.test = {};

wrist.watch(input1, 'value', changeValue2);
wrist.watch(input1, 'value', changeGlobalTest);

wrist.watch(input2, 'value', changeValue1);
wrist.watch(input2, 'value', changeGlobalTest);

wrist.watch(global.test, 'value', changeValue1);
wrist.watch(global.test, 'value', changeValue2);
wrist.watch(window.test, 'value', changeValue1);
wrist.watch(window.test, 'value', changeValue2);

global.test.value = 'change value';
test.value = 'change value';

try { console.log('try: test.value = 132;'); } catch(o_O) {}
5 changes: 2 additions & 3 deletions examples/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
h1 { font-size: 1.2em; }
input { display: block; margin: 8px auto; }
</style>
<script>window.Promise||document.write('<script src="js-browser/promise-pjs.js"><'+'/script>')</script>
<script>process={browser:true}</script>
<script defer src="../wrist.min.js"></script>
</head>
<body>
<input name="title">
<input type="checkbox" name="published">
</body>
<script defer id="common-js" data-main="./post.js" src="https://unpkg.com/common-js@0.3.5/common.js"></script>
<script defer src="post.js"></script>
</html>
5 changes: 0 additions & 5 deletions examples/post.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var wrist = require('../wrist');

var post = {
title: '',
published: false
Expand All @@ -23,6 +21,3 @@ wrist.watch(title, 'value', function (prop, old, val) {
wrist.watch(published, 'checked', function (prop, old, val) {
post.published = val;
});

// for testing purpose through console
global.post = post;

0 comments on commit eaefddd

Please sign in to comment.