Skip to content
This repository was archived by the owner on May 19, 2025. It is now read-only.

Commit b84749f

Browse files
committed
Add query property to _firestoreProps in FirestoreMixin.
1 parent 4328fd0 commit b84749f

1 file changed

Lines changed: 20 additions & 15 deletions

File tree

firebase-firestore-mixin.html

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,38 +141,43 @@
141141
connectedCallback() {
142142
const props = collect(this.constructor, 'properties');
143143
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);
148147
}
149148
}
150149
super.connectedCallback();
151150
}
152151

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';
157160

158161
this._firestoreProps[name] = config;
159162

160163
// Create a method observer that will be called every time a templatized or observed property changes
161164
let args = config.props.concat(config.observes).join(',');
162165
if (args.length) { args = ',' + args; }
163-
this._createMethodObserver(`_firestoreUpdateBinding('${type}','${name}'${args})`);
166+
this._createMethodObserver(`_firestoreUpdateBinding('${name}'${args})`);
164167

165168
if (!config.props.length && !config.observes.length) {
166-
this._firestoreUpdateBinding(type,name);
169+
this._firestoreUpdateBinding(name);
167170
}
168171
}
169172

170-
_firestoreUpdateBinding(type, name) {
173+
_firestoreUpdateBinding(name, ...args) {
171174
this._firestoreUnlisten(name);
172175

173176
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)
176181

177182
if (propArgs.length < config.props.length || observesArgs.length < config.observes.length) {
178183
this[name] = null;
@@ -183,11 +188,11 @@
183188

184189
const collPath = stitch(config.literals, propArgs);
185190
const assigner = snap => {
186-
this[name] = TRANSFORMS[type](snap);
191+
this[name] = TRANSFORMS[config.type](snap);
187192
this[name + 'Ready'] = true;
188193
}
189194

190-
let ref = this.db[type](collPath);
195+
let ref = this.db[config.type](collPath);
191196
this[name + 'Ref'] = ref;
192197
this[name + 'Ready'] = false;
193198

0 commit comments

Comments
 (0)