|
| 1 | +<!-- |
| 2 | +@license |
| 3 | +Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 4 | +This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt |
| 5 | +The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 6 | +The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt |
| 7 | +Code distributed by Google as part of the polymer project is also |
| 8 | +subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt |
| 9 | +--> |
| 10 | +<link rel="import" href="../../polymer/polymer.html"> |
| 11 | +<link rel="import" href="../firebase-element.html"> |
| 12 | +<link rel="import" href="../firebase.html"> |
| 13 | +<dom-module id="x-firebase"> |
| 14 | + <template> |
| 15 | + <firebase-element id="base" on-data-change="onDataChange" data="{{data}}" location="https://treedata-demo.firebaseio.com/demo" log></firebase-element> |
| 16 | + |
| 17 | + <h3>Top-level properties persist automatically:</h3> |
| 18 | + |
| 19 | + <input value="{{data.name::input}}"> |
| 20 | + <br> |
| 21 | + <input value="{{data.info::input}}"> |
| 22 | + |
| 23 | + <hr> |
| 24 | + |
| 25 | + <h3>Nested properties must be persisted manually:</h3> |
| 26 | + |
| 27 | + <input value="{{data.more.color::input}}"> |
| 28 | + |
| 29 | + <button on-tap="onCommitMore">Commit data.more</button> |
| 30 | + |
| 31 | + <hr> |
| 32 | + |
| 33 | + <h3>Remote Data</h3> |
| 34 | + <pre>{{json}}</pre> |
| 35 | + |
| 36 | + <hr> |
| 37 | + |
| 38 | + <button on-tap="onResetLocal">Reset Local</button> |
| 39 | + <button on-tap="onRemoveLocal">Remove Local</button> |
| 40 | + <button on-tap="onResetRemote">Reset remote</button> |
| 41 | + <button on-tap="onRemoveRemote">Remove Remote</button> |
| 42 | + |
| 43 | + </template> |
| 44 | +</dom-module> |
| 45 | +<script> |
| 46 | + Polymer({ |
| 47 | + is: 'x-firebase', |
| 48 | + |
| 49 | + properties: { |
| 50 | + data: { |
| 51 | + type: Object, |
| 52 | + notify: true, |
| 53 | + observer: 'dataChanged' |
| 54 | + }, |
| 55 | + |
| 56 | + json: { |
| 57 | + type: Object |
| 58 | + } |
| 59 | + }, |
| 60 | + |
| 61 | + onResetLocal: function() { |
| 62 | + // direct setting of data is persisted automatically |
| 63 | + this.data = { |
| 64 | + name: 'anonymous', |
| 65 | + info: 'none', |
| 66 | + more: { |
| 67 | + color: "yellow" |
| 68 | + } |
| 69 | + }; |
| 70 | + }, |
| 71 | + |
| 72 | + onRemoveLocal: function() { |
| 73 | + this.data = null; |
| 74 | + }, |
| 75 | + |
| 76 | + onResetRemote: function() { |
| 77 | + // Simulate other actor setting data to same remote location |
| 78 | + new Firebase('https://treedata-demo.firebaseio.com/demo').set({ |
| 79 | + name: 'anonymous', |
| 80 | + info: 'none', |
| 81 | + more: { |
| 82 | + color: "yellow" |
| 83 | + } |
| 84 | + }); |
| 85 | + }, |
| 86 | + |
| 87 | + onCommitMore: function() { |
| 88 | + this.$.base.commitProperty('more'); |
| 89 | + }, |
| 90 | + |
| 91 | + dataChanged: function() { |
| 92 | + this.json = JSON.stringify(this.data, null, ' '); |
| 93 | + } |
| 94 | + }); |
| 95 | +</script> |
0 commit comments