|
141 | 141 | connectedCallback() { |
142 | 142 | const props = collect(this.constructor, 'properties'); |
143 | 143 | for (let name in props) { |
144 | | - if (props[name].doc) { |
145 | | - this._firestoreBind('doc', props[name].doc, name, props[name].live, props[name].observes); |
146 | | - } else if (props[name].collection) { |
147 | | - this._firestoreBind('collection', props[name].collection, name, props[name].live, props[name].observes); |
| 144 | + const options = props[name]; |
| 145 | + if (options.doc || options.collection) { |
| 146 | + this._firestoreBind(name, options); |
148 | 147 | } |
149 | 148 | } |
150 | 149 | super.connectedCallback(); |
151 | 150 | } |
152 | 151 |
|
153 | | - _firestoreBind(type, path, name, live = false, observes = []) { |
154 | | - const config = parsePath(path); |
155 | | - config.observes = observes; |
156 | | - config.live = live; |
| 152 | + _firestoreBind(name, options) { |
| 153 | + const defaults = { |
| 154 | + live: false, |
| 155 | + observes: [], |
| 156 | + } |
| 157 | + const parsedPath = parsePath(options.doc || options.collection); |
| 158 | + const config = Object.assign({}, defaults, options, parsedPath); |
| 159 | + config.type = config.doc ? 'doc' : 'collection'; |
157 | 160 |
|
158 | 161 | this._firestoreProps[name] = config; |
159 | 162 |
|
160 | 163 | // Create a method observer that will be called every time a templatized or observed property changes |
161 | 164 | let args = config.props.concat(config.observes).join(','); |
162 | 165 | if (args.length) { args = ',' + args; } |
163 | | - this._createMethodObserver(`_firestoreUpdateBinding('${type}','${name}'${args})`); |
| 166 | + this._createMethodObserver(`_firestoreUpdateBinding('${name}'${args})`); |
164 | 167 |
|
165 | 168 | if (!config.props.length && !config.observes.length) { |
166 | | - this._firestoreUpdateBinding(type,name); |
| 169 | + this._firestoreUpdateBinding(name); |
167 | 170 | } |
168 | 171 | } |
169 | 172 |
|
170 | | - _firestoreUpdateBinding(type, name) { |
| 173 | + _firestoreUpdateBinding(name, ...args) { |
171 | 174 | this._firestoreUnlisten(name); |
172 | 175 |
|
173 | 176 | const config = this._firestoreProps[name]; |
174 | | - const propArgs = Array.prototype.slice.call(arguments, 2, config.props.length + 2).filter(arg => arg); |
175 | | - const observesArgs = Array.prototype.slice.call(arguments, config.props.length + 2).filter(arg => arg); |
| 177 | + const isDefined = (x) => x !== undefined; |
| 178 | + const propArgs = args.slice(0, config.props.length).filter(isDefined); |
| 179 | + const observesArgs = args.slice(config.props.length).filter(isDefined); |
| 180 | + console.log(args, propArgs, observesArgs) |
176 | 181 |
|
177 | 182 | if (propArgs.length < config.props.length || observesArgs.length < config.observes.length) { |
178 | 183 | this[name] = null; |
|
183 | 188 |
|
184 | 189 | const collPath = stitch(config.literals, propArgs); |
185 | 190 | const assigner = snap => { |
186 | | - this[name] = TRANSFORMS[type](snap); |
| 191 | + this[name] = TRANSFORMS[config.type](snap); |
187 | 192 | this[name + 'Ready'] = true; |
188 | 193 | } |
189 | 194 |
|
190 | | - let ref = this.db[type](collPath); |
| 195 | + let ref = this.db[config.type](collPath); |
191 | 196 | this[name + 'Ref'] = ref; |
192 | 197 | this[name + 'Ready'] = false; |
193 | 198 |
|
|
0 commit comments