Skip to content

Commit 44e4322

Browse files
committed
docs: add method observation example
1 parent bdeb7ef commit 44e4322

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

examples/observing-methods.html

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf8" />
5+
<title>localForage-observable method observation example</title>
6+
</head>
7+
<body>
8+
<script src="../bower_components/localforage/dist/localforage.js"></script>
9+
<script src="../node_modules/zen-observable/zen-observable.js"></script>
10+
<script src="../src/localforage-observable.js"></script>
11+
<script>
12+
localforage.ready(function() {
13+
var methodCallObservable = localforage.newObservable({
14+
setItem: true,
15+
changeDetection: false
16+
});
17+
18+
var methodCallSubscription = methodCallObservable.subscribe({
19+
next: function(args) {
20+
console.log('Method ' + args.methodName + ' was called.', args );
21+
}
22+
});
23+
24+
localforage.setItem('UserProfile', {
25+
UserName: 'user1',
26+
Password: '12345'
27+
}).then(function(){
28+
return localforage.setItem('UserProfile', {
29+
UserName: 'user1',
30+
Password: '67890'
31+
});
32+
}).then(function(){
33+
// this should not notify the subscribers
34+
return localforage.setItem('UserProfile', {
35+
UserName: 'user1',
36+
Password: '67890'
37+
});
38+
}).then(function() {
39+
40+
return localforage.setItem('test1', 'value1');
41+
}).then(function() {
42+
return localforage.setItem('test2', 'value2');
43+
}).then(function() {
44+
return localforage.setItem('test2', 'value2b');
45+
}).then(function() {
46+
// this should not notify the subscribers
47+
return localforage.setItem('test2', 'value2b');
48+
}).then(function() {
49+
return localforage.setItem('test3', 'value3');
50+
}).then(function() {
51+
return localforage.clear();
52+
}).then(function() {
53+
methodCallSubscription.unsubscribe();
54+
});
55+
});
56+
</script>
57+
58+
<p>
59+
Check your console log.
60+
</p>
61+
</body>
62+
</html>

0 commit comments

Comments
 (0)