Skip to content

Commit

Permalink
docs: add method observation example
Browse files Browse the repository at this point in the history
  • Loading branch information
thgreasi committed Apr 28, 2016
1 parent bdeb7ef commit 44e4322
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions examples/observing-methods.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!doctype html>
<html>
<head>
<meta charset="utf8" />
<title>localForage-observable method observation example</title>
</head>
<body>
<script src="../bower_components/localforage/dist/localforage.js"></script>
<script src="../node_modules/zen-observable/zen-observable.js"></script>
<script src="../src/localforage-observable.js"></script>
<script>
localforage.ready(function() {
var methodCallObservable = localforage.newObservable({
setItem: true,
changeDetection: false
});

var methodCallSubscription = methodCallObservable.subscribe({
next: function(args) {
console.log('Method ' + args.methodName + ' was called.', args );
}
});

localforage.setItem('UserProfile', {
UserName: 'user1',
Password: '12345'
}).then(function(){
return localforage.setItem('UserProfile', {
UserName: 'user1',
Password: '67890'
});
}).then(function(){
// this should not notify the subscribers
return localforage.setItem('UserProfile', {
UserName: 'user1',
Password: '67890'
});
}).then(function() {

return localforage.setItem('test1', 'value1');
}).then(function() {
return localforage.setItem('test2', 'value2');
}).then(function() {
return localforage.setItem('test2', 'value2b');
}).then(function() {
// this should not notify the subscribers
return localforage.setItem('test2', 'value2b');
}).then(function() {
return localforage.setItem('test3', 'value3');
}).then(function() {
return localforage.clear();
}).then(function() {
methodCallSubscription.unsubscribe();
});
});
</script>

<p>
Check your console log.
</p>
</body>
</html>

0 comments on commit 44e4322

Please sign in to comment.