Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add query property to _firestoreProps in FirestoreMixin. #303

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions firebase-firestore-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,40 @@
connectedCallback() {
const props = collect(this.constructor, 'properties');
for (let name in props) {
if (props[name].doc) {
this._firestoreBind('doc', props[name].doc, name, props[name].live, props[name].observes);
} else if (props[name].collection) {
this._firestoreBind('collection', props[name].collection, name, props[name].live, props[name].observes);
const options = props[name];
if (options.doc || options.collection) {
this._firestoreBind(name, options);
}
}
super.connectedCallback();
}

_firestoreBind(type, path, name, live = false, observes = []) {
const config = parsePath(path);
config.observes = observes;
config.live = live;
_firestoreBind(name, options) {
const defaults = {
live: false,
observes: [],
}
const parsedPath = parsePath(options.doc || options.collection);
const config = Object.assign({}, defaults, options, parsedPath);
config.type = config.doc ? 'doc' : 'collection';

this._firestoreProps[name] = config;

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

if (!config.props.length && !config.observes.length) {
this._firestoreUpdateBinding(type,name);
}
this._firestoreUpdateBinding(type,name);
}

_firestoreUpdateBinding(type, name) {
_firestoreUpdateBinding(name, ...args) {
this._firestoreUnlisten(name);

const config = this._firestoreProps[name];
const propArgs = Array.prototype.slice.call(arguments, 2, config.props.length + 2).filter(arg => arg);
const observesArgs = Array.prototype.slice.call(arguments, config.props.length + 2).filter(arg => arg);
const isDefined = (x) => x !== undefined;
const propArgs = args.slice(0, config.props.length).filter(isDefined);
const observesArgs = args.slice(config.props.length).filter(isDefined);

if (propArgs.length < config.props.length || observesArgs.length < config.observes.length) {
this[name] = null;
Expand All @@ -183,11 +185,11 @@

const collPath = stitch(config.literals, propArgs);
const assigner = snap => {
this[name] = TRANSFORMS[type](snap);
this[name] = TRANSFORMS[config.type](snap);
this[name + 'Ready'] = true;
}

let ref = this.db[type](collPath);
let ref = this.db[config.type](collPath);
this[name + 'Ref'] = ref;
this[name + 'Ready'] = false;

Expand Down