emberfire
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -238,3 +238,3 @@ import Ember from 'ember'; | ||
} else { | ||
ref.orderByChild(query.orderBy); | ||
ref = ref.orderByChild(query.orderBy); | ||
} | ||
@@ -241,0 +241,0 @@ |
@@ -6,3 +6,3 @@ import Ember from 'ember'; | ||
var VERSION = '1.4.1'; | ||
var VERSION = '1.4.2'; | ||
@@ -9,0 +9,0 @@ if (Ember.libraries) { |
@@ -1,1 +0,1 @@ | ||
fixed - Add `chalk` dependency to fix the addon install process. | ||
fixed - Fixed an issue where `orderBy: 'property'` queries were not working. |
@@ -246,3 +246,3 @@ (function() { | ||
} else { | ||
ref.orderByChild(query.orderBy); | ||
ref = ref.orderByChild(query.orderBy); | ||
} | ||
@@ -735,3 +735,3 @@ | ||
var $$$$$$addon$initializers$emberfire$$VERSION = '1.4.1'; | ||
var $$$$$$addon$initializers$emberfire$$VERSION = '1.4.2'; | ||
@@ -795,3 +795,3 @@ if (ember$$default.libraries) { | ||
* | ||
* EmberFire 1.4.1 | ||
* EmberFire 1.4.2 | ||
* https://github.com/firebase/emberfire/ | ||
@@ -798,0 +798,0 @@ * License: MIT |
@@ -1,2 +0,2 @@ | ||
(function(){"use strict";var e=window.Ember,r=window.DS,t=function(r,t,i,n){var o=i||[];return new e.RSVP.Promise(function(e,i){var a=function(r){r?(n&&"object"==typeof r&&(r.location=n),i(r)):e()};o.push(a),r.apply(t,o)})},i=e.String.fmt,n=e.RSVP.Promise,o=e.EnumerableUtils.forEach,a=e.EnumerableUtils.filter,s=e.EnumerableUtils.map,d=e.EnumerableUtils.indexOf,u=function(r){var t=e.A();return r.forEach(function(e){d(t,e)<0&&t.push(e)}),t},l=r.Adapter.extend(e.Evented,{defaultSerializer:"-firebase",init:function(){var e=this.get("firebase");if(!e||"object"!=typeof e)throw new Error("Please set the `firebase` property on the adapter.");this._ref=e.ref(),this._findAllMapForType={},this._recordCacheForType={},this._queue=[]},generateIdForRecord:function(){return this._getKey(this._ref.push())},_assignIdToPayload:function(e){var r=e.val();return null!==r&&"object"==typeof r&&"undefined"==typeof r.id&&(r.id=this._getKey(e)),r},find:function(e,r,t){var o=this,a=this._getRef(r,t);return new n(function(e,n){a.once("value",function(s){var d=o._assignIdToPayload(s);if(o._updateRecordCacheForType(r,d),null===d){var u=new Error(i("no record was found at %@",[a.toString()]));u.recordId=t,n(u)}else e(d)},function(e){n(e)})},i("DS: FirebaseAdapter#find %@ to %@",[r,a.toString()]))},recordWasPushed:function(e,r,t){t.__listening||this.listenForChanges(e,r,t)},recordWillUnload:function(e,r){var t=this._getRef(r.typeKey,r.get("id"));t.off("value")},recordWillDelete:function(e,r){var t=this;r.eachRelationship(function(i,n){if("belongsTo"===n.kind){var o=r.get(n.key),a=r.inverseFor(n.key);if(a&&o.get("id")){var s=t._getRef(a.type,o.get("id"));t._removeHasManyRecord(e,s,a.name,r.id)}}})},listenForChanges:function(e,r,t){t.__listening=!0;var i=e.serializerFor(r),n=this,o=this._getRef(r,t.get("id")),a=!1;o.on("value",function(t){a&&n._handleChildValue(e,r,i,t),a=!0})},findMany:void 0,findAll:function(e,r){var t=this,o=this._getRef(r);return new n(function(i,n){o.once("value",function(n){t._findAllHasEventsForType(r)||t._findAllAddEventListeners(e,r,o);var a=[];n.forEach(function(e){var i=t._assignIdToPayload(e);t._updateRecordCacheForType(r,i),a.push(i)}),i(a)},function(e){n(e)})},i("DS: FirebaseAdapter#findAll %@ to %@",[r,o.toString()]))},findQuery:function(e,r,t){var o=this,a=this._getRef(r);return a=this.applyQueryToRef(a,t),new n(function(t,i){a.once("value",function(i){o._findAllHasEventsForType(r)||o._findAllAddEventListeners(e,r,a);var n=[];i.forEach(function(e){var t=o._assignIdToPayload(e);o._updateRecordCacheForType(r,t),n.push(t)}),t(n)},function(e){i(e)})},i("DS: FirebaseAdapter#findQuery %@ with %@",[r,t]))},applyQueryToRef:function(e,r){return r.orderBy||(r.orderBy="_key"),"_key"===r.orderBy?e=e.orderByKey():"_value"===r.orderBy?e=e.orderByValue():"_priority"===r.orderBy?e=e.orderByPriority():e.orderByChild(r.orderBy),["limitToFirst","limitToLast","startAt","endAt","equalTo"].forEach(function(t){(r[t]||""===r[t])&&(e=e[t](r[t]))}),e},_findAllMapForType:void 0,_findAllHasEventsForType:function(r){return!e.isNone(this._findAllMapForType[r])},_findAllAddEventListeners:function(e,r,t){this._findAllMapForType[r]=!0;var i=this,n=e.serializerFor(r);t.on("child_added",function(t){e.hasRecordForId(r,i._getKey(t))||i._handleChildValue(e,r,n,t)})},_handleChildValue:function(e,r,t,i){if(!e.isDestroying){var n=i.val();if(null===n){var o=this._getKey(i),a=e.getById(r,o);a.get("isDeleted")||a.deleteRecord()}else{var s=this._assignIdToPayload(i);this._enqueue(function(){e.push(r,t.extractSingle(e,r,s))})}}},createRecord:function(e,r,t){var i=this;return this.updateRecord(e,r,t).then(function(){i.listenForChanges(e,r,t)})},updateRecord:function(r,t,o,a){var s=this,d=a||this._getRef(t,o.id),u=s._getRecordCache(t.typeKey,o.get("id")),l=o.serialize({includeId:!1});return new n(function(n,a){var c=e.A();o.eachRelationship(function(e,i){var n;"hasMany"===i.kind?l[e]&&(n=s._saveHasManyRelationship(r,t,i,l[e],d,u),c.push(n),delete l[e]):i.options.embedded===!0&&l[e]&&(n=s._saveBelongsToRecord(r,t,i,l[e],d),c.push(n),delete l[e])});var h=e.RSVP.allSettled(c),f=s._updateRecord(d,l);e.RSVP.hashSettled({relationships:h,record:f}).then(function(r){var s=e.A(r.relationships.value).filterBy("state","rejected");if("rejected"===r.record.state&&s.push(r.record),0!==s.length){var d=new Error(i("Some errors were encountered while saving %@ %@",[t,o.id]));d.errors=s.mapBy("reason"),a(d)}else n()})},i("DS: FirebaseAdapter#updateRecord %@ to %@",[t,d.toString()]))},_updateRecord:function(e,r){return t(e.update,e,[r])},_saveHasManyRelationship:function(r,t,n,o,d,l){if(!e.isArray(o))throw new Error("hasMany relationships must must be an array");var c=this,h=e.A(l[n.key]),f=[],y=a(o,function(e){return!h.contains(e)});f=a(o,function(e){var t=n.type;return r.hasRecordForId(t,e)&&r.getById(t,e).get("isDirty")===!0}),f=s(u(f.concat(y)),function(e){return c._saveHasManyRecord(r,n,d,e)});var p=a(h,function(e){return!o.contains(e)});p=s(p,function(e){return c._removeHasManyRecord(r,d,n.key,e)});var v=f.concat(p);return e.RSVP.allSettled(v).then(function(r){var t=e.A(e.A(r).filterBy("state","rejected"));if(0===t.get("length"))return l[n.key]=o,r;var a=new Error(i("Some errors were encountered while saving a hasMany relationship %@ -> %@",[n.parentType,n.type]));throw a.errors=e.A(t).mapBy("reason"),a})},_saveHasManyRecord:function(e,r,i,n){var o=this._getRelationshipRef(i,r.key,n),a=e.getById(r.type,n),s=r.options.embedded===!0;return s?this.updateRecord(e,r.type,a,o):t(o.set,o,[!0])},_removeHasManyRecord:function(e,r,i,n){var o=this._getRelationshipRef(r,i,n);return t(o.remove,o,[],o.toString())},_saveBelongsToRecord:function(e,r,t,i,n){var o=n.child(t.key),a=e.getById(t.type,i);return this.updateRecord(e,t.type,a,o)},deleteRecord:function(e,r,i){var n=this._getRef(r,i.get("id"));return t(n.remove,n)},pathForType:function(r){var t=e.String.camelize(r);return e.String.pluralize(t)},_getRef:function(e,r){var t=this._ref;return e&&(t=t.child(this.pathForType(e.typeKey))),r&&(t=t.child(r)),t},_getRelationshipRef:function(e,r,t){return e.child(r).child(t)},_queueFlushDelay:1e3/60,_queueScheduleFlush:function(){e.run.later(this,this._queueFlush,this._queueFlushDelay)},_queueFlush:function(){o(this._queue,function(e){var r=e[0],t=e[1];r.apply(null,t)}),this._queue.length=0},_enqueue:function(e,r){if(this._queueFlushDelay){var t=this._queue.push([e,r]);1===t&&this._queueScheduleFlush()}else e.apply(null,r)},_recordCacheForType:void 0,_updateRecordCacheForType:function(r,t){if(t){var i=t.id,n=r.typeKey,o=this._getRecordCache(n,i);r.eachRelationship(function(r,i){if("hasMany"===i.kind){var n=t[r];o[r]=e.isNone(n)?e.A():e.A(e.keys(n))}})}},_getRecordCache:function(e,r){var t=this._recordCacheForType;return t[e]=t[e]||{},t[e][r]=t[e][r]||{},t[e][r]},_getKey:function(e){return"function"==typeof e.key?e.key():e.name()}}),c=e.EnumerableUtils.map,h=e.String.fmt,f=r.JSONSerializer.extend(e.Evented,{_normalizeNumberIDs:function(e,r){var t=[];e[r][0]===!0&&t.push("0"),e[r][1]===!0&&t.push("1"),e[r]=t},normalizeHasMany:function(r,t,i){var n=i.key;if("object"!=typeof t[n]||e.isArray(t[n])){if(e.isArray(t[n])&&t[n].length<3&&(t[n][0]===!0||t[n][1]===!0))this._normalizeNumberIDs(t,n);else if(e.isArray(t[n]))throw new Error(h('%@ relationship %@(\'%@\') must be a key/value map in Firebase. Example: { "%@": { "%@_id": true } }',[r.toString(),i.kind,i.type.typeKey,n,i.type.typeKey]))}else t[n]=e.keys(t[n])},normalizeEmbeddedHasMany:function(r,t,i){var n,o=i.key,a=t[o];if(t[o]){for(n in a){var s=a[n];null!==s&&"object"==typeof s&&(s.id=n),this.store.push(i.type,this.normalize(i.type,s))}t[o]=e.keys(t[o])}},normalizeEmbeddedBelongsTo:function(e,r,t){var i=t.key;if(r[i]){var n=r[i];if("string"!=typeof n.id)throw new Error(h('Embedded relationship "%@" of "%@" must contain an "id" property in the payload',[t.type.typeKey,e]));this.store.push(t.type,this.normalize(t.type,n)),r[i]=n.id}},normalizeBelongsTo:e.K,normalize:function(e,r){var t=this;return e.eachRelationship(function(i,n){"hasMany"===n.kind?n.options.embedded?t.normalizeEmbeddedHasMany(e,r,n):t.normalizeHasMany(e,r,n):n.options.embedded?t.normalizeEmbeddedBelongsTo(e,r,n):t.normalizeBelongsTo(e,r,n)}),this._super.apply(this,arguments)},extractSingle:function(e,r,t){return this.normalize(r,t)},extractArray:function(e,r,t){return c(t,function(t){return this.extractSingle(e,r,t)},this)},serializeHasMany:function(r,t,i){var n=i.key,o=this.keyForRelationship?this.keyForRelationship(n,"hasMany"):n;t[o]=e.A(r.get(n)).mapBy("id")},serializeBelongsTo:function(e,r,t){this._super(e,r,t);var i=t.key;("undefined"==typeof r[i]||""===r[i])&&delete r[i]}}),y="1.4.1";e.libraries&&e.libraries.registerCoreLibrary("EmberFire",y);var p={name:"emberfire",initialize:function(e,t){t.register("adapter:-firebase",l),t.register("serializer:-firebase",f),r.Store.reopen({push:function(e,r,t){var i=this._super(e,r,t),n=this.adapterFor(i.constructor);return n.recordWasPushed&&n.recordWasPushed(this,e,i),i},recordWillUnload:function(e){var r=this.adapterFor(e.constructor);r.recordWillUnload&&r.recordWillUnload(this,e)},recordWillDelete:function(e){var r=this.adapterFor(e.constructor);r.recordWillDelete&&r.recordWillDelete(this,e)}}),r.Model.reopen({unloadRecord:function(){return this.store.recordWillUnload(this),this._super()},deleteRecord:function(){this.store.recordWillDelete(this),this._super()}}),r.FirebaseAdapter=l,r.FirebaseSerializer=f}};/*! | ||
(function(){"use strict";var e=window.Ember,r=window.DS,t=function(r,t,i,n){var o=i||[];return new e.RSVP.Promise(function(e,i){var a=function(r){r?(n&&"object"==typeof r&&(r.location=n),i(r)):e()};o.push(a),r.apply(t,o)})},i=e.String.fmt,n=e.RSVP.Promise,o=e.EnumerableUtils.forEach,a=e.EnumerableUtils.filter,s=e.EnumerableUtils.map,d=e.EnumerableUtils.indexOf,u=function(r){var t=e.A();return r.forEach(function(e){d(t,e)<0&&t.push(e)}),t},l=r.Adapter.extend(e.Evented,{defaultSerializer:"-firebase",init:function(){var e=this.get("firebase");if(!e||"object"!=typeof e)throw new Error("Please set the `firebase` property on the adapter.");this._ref=e.ref(),this._findAllMapForType={},this._recordCacheForType={},this._queue=[]},generateIdForRecord:function(){return this._getKey(this._ref.push())},_assignIdToPayload:function(e){var r=e.val();return null!==r&&"object"==typeof r&&"undefined"==typeof r.id&&(r.id=this._getKey(e)),r},find:function(e,r,t){var o=this,a=this._getRef(r,t);return new n(function(e,n){a.once("value",function(s){var d=o._assignIdToPayload(s);if(o._updateRecordCacheForType(r,d),null===d){var u=new Error(i("no record was found at %@",[a.toString()]));u.recordId=t,n(u)}else e(d)},function(e){n(e)})},i("DS: FirebaseAdapter#find %@ to %@",[r,a.toString()]))},recordWasPushed:function(e,r,t){t.__listening||this.listenForChanges(e,r,t)},recordWillUnload:function(e,r){var t=this._getRef(r.typeKey,r.get("id"));t.off("value")},recordWillDelete:function(e,r){var t=this;r.eachRelationship(function(i,n){if("belongsTo"===n.kind){var o=r.get(n.key),a=r.inverseFor(n.key);if(a&&o.get("id")){var s=t._getRef(a.type,o.get("id"));t._removeHasManyRecord(e,s,a.name,r.id)}}})},listenForChanges:function(e,r,t){t.__listening=!0;var i=e.serializerFor(r),n=this,o=this._getRef(r,t.get("id")),a=!1;o.on("value",function(t){a&&n._handleChildValue(e,r,i,t),a=!0})},findMany:void 0,findAll:function(e,r){var t=this,o=this._getRef(r);return new n(function(i,n){o.once("value",function(n){t._findAllHasEventsForType(r)||t._findAllAddEventListeners(e,r,o);var a=[];n.forEach(function(e){var i=t._assignIdToPayload(e);t._updateRecordCacheForType(r,i),a.push(i)}),i(a)},function(e){n(e)})},i("DS: FirebaseAdapter#findAll %@ to %@",[r,o.toString()]))},findQuery:function(e,r,t){var o=this,a=this._getRef(r);return a=this.applyQueryToRef(a,t),new n(function(t,i){a.once("value",function(i){o._findAllHasEventsForType(r)||o._findAllAddEventListeners(e,r,a);var n=[];i.forEach(function(e){var t=o._assignIdToPayload(e);o._updateRecordCacheForType(r,t),n.push(t)}),t(n)},function(e){i(e)})},i("DS: FirebaseAdapter#findQuery %@ with %@",[r,t]))},applyQueryToRef:function(e,r){return r.orderBy||(r.orderBy="_key"),e="_key"===r.orderBy?e.orderByKey():"_value"===r.orderBy?e.orderByValue():"_priority"===r.orderBy?e.orderByPriority():e.orderByChild(r.orderBy),["limitToFirst","limitToLast","startAt","endAt","equalTo"].forEach(function(t){(r[t]||""===r[t])&&(e=e[t](r[t]))}),e},_findAllMapForType:void 0,_findAllHasEventsForType:function(r){return!e.isNone(this._findAllMapForType[r])},_findAllAddEventListeners:function(e,r,t){this._findAllMapForType[r]=!0;var i=this,n=e.serializerFor(r);t.on("child_added",function(t){e.hasRecordForId(r,i._getKey(t))||i._handleChildValue(e,r,n,t)})},_handleChildValue:function(e,r,t,i){if(!e.isDestroying){var n=i.val();if(null===n){var o=this._getKey(i),a=e.getById(r,o);a.get("isDeleted")||a.deleteRecord()}else{var s=this._assignIdToPayload(i);this._enqueue(function(){e.push(r,t.extractSingle(e,r,s))})}}},createRecord:function(e,r,t){var i=this;return this.updateRecord(e,r,t).then(function(){i.listenForChanges(e,r,t)})},updateRecord:function(r,t,o,a){var s=this,d=a||this._getRef(t,o.id),u=s._getRecordCache(t.typeKey,o.get("id")),l=o.serialize({includeId:!1});return new n(function(n,a){var c=e.A();o.eachRelationship(function(e,i){var n;"hasMany"===i.kind?l[e]&&(n=s._saveHasManyRelationship(r,t,i,l[e],d,u),c.push(n),delete l[e]):i.options.embedded===!0&&l[e]&&(n=s._saveBelongsToRecord(r,t,i,l[e],d),c.push(n),delete l[e])});var h=e.RSVP.allSettled(c),f=s._updateRecord(d,l);e.RSVP.hashSettled({relationships:h,record:f}).then(function(r){var s=e.A(r.relationships.value).filterBy("state","rejected");if("rejected"===r.record.state&&s.push(r.record),0!==s.length){var d=new Error(i("Some errors were encountered while saving %@ %@",[t,o.id]));d.errors=s.mapBy("reason"),a(d)}else n()})},i("DS: FirebaseAdapter#updateRecord %@ to %@",[t,d.toString()]))},_updateRecord:function(e,r){return t(e.update,e,[r])},_saveHasManyRelationship:function(r,t,n,o,d,l){if(!e.isArray(o))throw new Error("hasMany relationships must must be an array");var c=this,h=e.A(l[n.key]),f=[],y=a(o,function(e){return!h.contains(e)});f=a(o,function(e){var t=n.type;return r.hasRecordForId(t,e)&&r.getById(t,e).get("isDirty")===!0}),f=s(u(f.concat(y)),function(e){return c._saveHasManyRecord(r,n,d,e)});var p=a(h,function(e){return!o.contains(e)});p=s(p,function(e){return c._removeHasManyRecord(r,d,n.key,e)});var v=f.concat(p);return e.RSVP.allSettled(v).then(function(r){var t=e.A(e.A(r).filterBy("state","rejected"));if(0===t.get("length"))return l[n.key]=o,r;var a=new Error(i("Some errors were encountered while saving a hasMany relationship %@ -> %@",[n.parentType,n.type]));throw a.errors=e.A(t).mapBy("reason"),a})},_saveHasManyRecord:function(e,r,i,n){var o=this._getRelationshipRef(i,r.key,n),a=e.getById(r.type,n),s=r.options.embedded===!0;return s?this.updateRecord(e,r.type,a,o):t(o.set,o,[!0])},_removeHasManyRecord:function(e,r,i,n){var o=this._getRelationshipRef(r,i,n);return t(o.remove,o,[],o.toString())},_saveBelongsToRecord:function(e,r,t,i,n){var o=n.child(t.key),a=e.getById(t.type,i);return this.updateRecord(e,t.type,a,o)},deleteRecord:function(e,r,i){var n=this._getRef(r,i.get("id"));return t(n.remove,n)},pathForType:function(r){var t=e.String.camelize(r);return e.String.pluralize(t)},_getRef:function(e,r){var t=this._ref;return e&&(t=t.child(this.pathForType(e.typeKey))),r&&(t=t.child(r)),t},_getRelationshipRef:function(e,r,t){return e.child(r).child(t)},_queueFlushDelay:1e3/60,_queueScheduleFlush:function(){e.run.later(this,this._queueFlush,this._queueFlushDelay)},_queueFlush:function(){o(this._queue,function(e){var r=e[0],t=e[1];r.apply(null,t)}),this._queue.length=0},_enqueue:function(e,r){if(this._queueFlushDelay){var t=this._queue.push([e,r]);1===t&&this._queueScheduleFlush()}else e.apply(null,r)},_recordCacheForType:void 0,_updateRecordCacheForType:function(r,t){if(t){var i=t.id,n=r.typeKey,o=this._getRecordCache(n,i);r.eachRelationship(function(r,i){if("hasMany"===i.kind){var n=t[r];o[r]=e.isNone(n)?e.A():e.A(e.keys(n))}})}},_getRecordCache:function(e,r){var t=this._recordCacheForType;return t[e]=t[e]||{},t[e][r]=t[e][r]||{},t[e][r]},_getKey:function(e){return"function"==typeof e.key?e.key():e.name()}}),c=e.EnumerableUtils.map,h=e.String.fmt,f=r.JSONSerializer.extend(e.Evented,{_normalizeNumberIDs:function(e,r){var t=[];e[r][0]===!0&&t.push("0"),e[r][1]===!0&&t.push("1"),e[r]=t},normalizeHasMany:function(r,t,i){var n=i.key;if("object"!=typeof t[n]||e.isArray(t[n])){if(e.isArray(t[n])&&t[n].length<3&&(t[n][0]===!0||t[n][1]===!0))this._normalizeNumberIDs(t,n);else if(e.isArray(t[n]))throw new Error(h('%@ relationship %@(\'%@\') must be a key/value map in Firebase. Example: { "%@": { "%@_id": true } }',[r.toString(),i.kind,i.type.typeKey,n,i.type.typeKey]))}else t[n]=e.keys(t[n])},normalizeEmbeddedHasMany:function(r,t,i){var n,o=i.key,a=t[o];if(t[o]){for(n in a){var s=a[n];null!==s&&"object"==typeof s&&(s.id=n),this.store.push(i.type,this.normalize(i.type,s))}t[o]=e.keys(t[o])}},normalizeEmbeddedBelongsTo:function(e,r,t){var i=t.key;if(r[i]){var n=r[i];if("string"!=typeof n.id)throw new Error(h('Embedded relationship "%@" of "%@" must contain an "id" property in the payload',[t.type.typeKey,e]));this.store.push(t.type,this.normalize(t.type,n)),r[i]=n.id}},normalizeBelongsTo:e.K,normalize:function(e,r){var t=this;return e.eachRelationship(function(i,n){"hasMany"===n.kind?n.options.embedded?t.normalizeEmbeddedHasMany(e,r,n):t.normalizeHasMany(e,r,n):n.options.embedded?t.normalizeEmbeddedBelongsTo(e,r,n):t.normalizeBelongsTo(e,r,n)}),this._super.apply(this,arguments)},extractSingle:function(e,r,t){return this.normalize(r,t)},extractArray:function(e,r,t){return c(t,function(t){return this.extractSingle(e,r,t)},this)},serializeHasMany:function(r,t,i){var n=i.key,o=this.keyForRelationship?this.keyForRelationship(n,"hasMany"):n;t[o]=e.A(r.get(n)).mapBy("id")},serializeBelongsTo:function(e,r,t){this._super(e,r,t);var i=t.key;("undefined"==typeof r[i]||""===r[i])&&delete r[i]}}),y="1.4.2";e.libraries&&e.libraries.registerCoreLibrary("EmberFire",y);var p={name:"emberfire",initialize:function(e,t){t.register("adapter:-firebase",l),t.register("serializer:-firebase",f),r.Store.reopen({push:function(e,r,t){var i=this._super(e,r,t),n=this.adapterFor(i.constructor);return n.recordWasPushed&&n.recordWasPushed(this,e,i),i},recordWillUnload:function(e){var r=this.adapterFor(e.constructor);r.recordWillUnload&&r.recordWillUnload(this,e)},recordWillDelete:function(e){var r=this.adapterFor(e.constructor);r.recordWillDelete&&r.recordWillDelete(this,e)}}),r.Model.reopen({unloadRecord:function(){return this.store.recordWillUnload(this),this._super()},deleteRecord:function(){this.store.recordWillDelete(this),this._super()}}),r.FirebaseAdapter=l,r.FirebaseSerializer=f}};/*! | ||
* EmberFire is the officially supported adapter for using Firebase with | ||
@@ -6,3 +6,3 @@ * Ember Data. The DS.FirebaseAdapter provides all of the standard DS.Adapter | ||
* | ||
* EmberFire 1.4.1 | ||
* EmberFire 1.4.2 | ||
* https://github.com/firebase/emberfire/ | ||
@@ -9,0 +9,0 @@ * License: MIT |
{ | ||
"name": "emberfire", | ||
"description": "The officially supported Ember binding for Firebase", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"author": "Firebase <support@firebase.com> (https://www.firebase.com/)", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/firebase/emberfire/", |
244
README.md
@@ -10,8 +10,4 @@ # EmberFire (Firebase + Ember Data) | ||
The `DS.FirebaseAdapter` provides all of the standard `DS.Adapter` methods and will automatically | ||
synchronize the store with Firebase. | ||
The `FirebaseAdapter` provides all of the standard `DS.Adapter` methods and will automatically synchronize the store with Firebase. **EmberFire is packaged as an addon with Ember CLI by default**, and is also available to use without the CLI. See below for instructions on getting started, and check out the full [EmberFire documentation](https://firebase.com/docs/web/libraries/ember/) on the Firebase website. EmberFire works with Ember Data beta.11 through beta.14.1 (and beta.15 but with deprecation warnings). | ||
If you would like to use Firebase without Ember Data, we recommend the third-party | ||
[ember-firebase](https://github.com/mjijackson/ember-firebase) binding. | ||
**Join the [Firebase + Ember Google Group](https://groups.google.com/forum/#!forum/firebase-ember) | ||
@@ -21,239 +17,37 @@ to ask technical questions, share apps you've built, and chat with other developers in the community.** | ||
## Downloading EmberFire | ||
## Installing EmberFire with the Ember CLI | ||
In order to use EmberFire in your project, you need to include the following files in your HTML: | ||
To install EmberFire as an addon with your Ember CLI app, run the following command within your app's directory: | ||
```html | ||
<!-- Ember + Ember Data --> | ||
<script src="http://builds.emberjs.com/tags/v1.9.1/ember.js"></script> | ||
<script src="http://builds.emberjs.com/tags/v1.0.0-beta.12/ember-data.js"></script> | ||
<!-- Firebase --> | ||
<script src="https://cdn.firebase.com/js/client/2.0.6/firebase.js"></script> | ||
<!-- EmberFire --> | ||
<script src="https://cdn.firebase.com/libs/emberfire/1.4.1/emberfire.min.js"></script> | ||
``` | ||
Use the URL above to download both the minified and non-minified versions of EmberFire from the | ||
Firebase CDN. You can also download them from the | ||
[releases page of this GitHub repository](https://github.com/firebase/emberfire/releases). | ||
[Firebase](https://www.firebase.com/docs/web/quickstart.html?utm_medium=web&utm_source=emberfire) and | ||
[Ember](http://emberjs.com/guides/getting-started/obtaining-emberjs-and-dependencies/) can be | ||
downloaded directly from their respective websites. | ||
You can also install EmberFire via Bower and its dependencies will be downloaded automatically: | ||
```bash | ||
$ bower install emberfire --save | ||
$ ember install:addon emberfire | ||
``` | ||
## Getting Started with Firebase | ||
This will add Firebase as a dependency in your `bower.json` file, create `app/adapters/application.js` and add configuration to `config/environment.js`. Now, update your firebase url in `config/environment.js`: | ||
EmberFire requires Firebase in order to sync data. You can | ||
[sign up here](https://www.firebase.com/signup/?utm_medium=web&utm_source=emberfire) for a free | ||
account. | ||
## Usage | ||
To get started, simply create an instance of the `DS.FirebaseAdapter` in your app: | ||
```javascript | ||
App.ApplicationAdapter = DS.FirebaseAdapter.extend({ | ||
firebase: new Firebase("https://<your-firebase>.firebaseio.com") | ||
}); | ||
``` | ||
Your Firebase data will now be synced with the Ember Data store. | ||
You can now interact with the data store as you normally would. For example, calling `find()` with | ||
a specific ID will retrieve that record from Firebase. Additionally, from that point on, every time | ||
that record is updated in Firebase, it will automatically be updated in the local data store. | ||
See the [Ember documentation](http://emberjs.com/guides/models/) for a full list of methods, | ||
including ways to create, find, delete and query records. | ||
#### Ember CLI | ||
EmberFire also works with the Ember CLI [Example App](https://github.com/stefanpenner/ember-cli-ember-fire). Run the following command to add `emberfire.js` to your project: | ||
Temporary install instructions for ember-cli: | ||
```bash | ||
$ npm install emberfire --save-dev | ||
$ ember generate emberfire | ||
``` | ||
Then, all you need to do is create `app/adapters/application.js` with the following content: | ||
```javascript | ||
/* globals Firebase */ | ||
export default DS.FirebaseAdapter.extend({ | ||
firebase: new Firebase("https://<your-firebase>.firebaseio.com") | ||
}); | ||
``` | ||
### Data Structure | ||
By default, EmberFire will try to determine the correct Firebase reference based on the model name. | ||
```javascript | ||
// Define a Post model | ||
App.Post = DS.Model.extend(); | ||
// Records will be fetched from to https://<your-firebase>.firebaseio.com/posts | ||
var posts = store.findAll("post"); | ||
// The new record will be saved to https://<your-firebase>.firebaseio.com/posts/post_id | ||
var newPost = store.createRecord("post").save(); | ||
``` | ||
#### What if my data is named differently? | ||
If you would like to customize where a model will be fetched/saved, simply create a model-specific | ||
adapter: | ||
```javascript | ||
// Define a Post model | ||
App.Post = DS.Model.extend(); | ||
// Define a Post adapter | ||
App.PostAdapter = App.ApplicationAdapter.extend({ | ||
pathForType: function(type) { | ||
return "custom-posts"; | ||
} | ||
}); | ||
``` | ||
Overriding the `pathForType()` method will allow you to tell the adapter where it should fetch/save | ||
records of the specified type. | ||
```javascript | ||
// Records will now be fetched from to https://<your-firebase>.firebaseio.com/custom-posts | ||
var posts = store.findAll("post"); | ||
// The new record will now be saved to https://<your-firebase>.firebaseio.com/custom-posts/post_id | ||
var newPost = store.createRecord("post").save(); | ||
``` | ||
### Relationships | ||
EmberFire can handle relationships in two different ways: async and embedded. | ||
#### Async | ||
Any relationship that is flagged as `async: true` tells the adapter to fetch the record if it | ||
hasn't already been loaded. | ||
```javascript | ||
App.Post = DS.Model.extend({ | ||
comments: DS.hasMany("comment", { async: true }) | ||
}); | ||
App.Comment = DS.Model.extend({ | ||
post: DS.belongsTo("post", { async: true }) | ||
}); | ||
``` | ||
In the `App.Post` example, comments will be fetched from `https://<your-firebase>.firebaseio.com/comments`. | ||
Here is what the data structure would look like in Firebase: | ||
```json | ||
{ | ||
"posts": { | ||
"post_id_1": { | ||
"comments": { | ||
"comment_id_1": true | ||
} | ||
} | ||
}, | ||
"comments": { | ||
"comment_id_1": { | ||
"body": "This is a comment", | ||
"post": "post_id_1" | ||
} | ||
} | ||
} | ||
``` | ||
**Note:** If your async data isn't auto-loading, make sure you've defined your relationships in | ||
both directions. | ||
#### Embedded | ||
Any relationship that is flagged as `embedded: true` tells the adapter that the related records | ||
have been included in the payload. | ||
Generally, this approach is more complicated and not as widely used, but it has been included to | ||
support existing data structures. | ||
##### `hasMany()` | ||
```javascript | ||
App.Post = DS.Model.extend({ | ||
comments: DS.hasMany("comment", { embedded: true }) | ||
}); | ||
``` | ||
Here is what the data structure would look like in Firebase: | ||
```json | ||
{ | ||
"posts": { | ||
"post_id_1": { | ||
"comments": { | ||
"comment_id_1": { | ||
"body": "This is a comment" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
**Note:** When a model has embedded relationships, the related model should not be saved on its own. | ||
```js | ||
var comment = store.createRecord("comment"); | ||
// This WILL NOT save the comment inside of the post because the adapter doesn't know | ||
// where to save the comment without the context of the post | ||
comment.save(); | ||
// config/environment.js | ||
module.exports = function(environment) { | ||
var ENV = { | ||
modulePrefix: 'firebase-app', | ||
environment: environment, | ||
firebase: 'https://YOUR-FIREBASE-NAME.firebaseio.com/', | ||
baseURL: '/', | ||
... | ||
``` | ||
Instead, the comment needs to be added to the post and then the post can be saved: | ||
Your Firebase data will now be synced with the Ember Data store. For detailed EmberFire documentation, check out the [quickstart](https://firebase.com/docs/web/libraries/ember/quickstart.html) or [guide](https://firebase.com/docs/web/libraries/ember/guide.html) in the Firebase docs. | ||
```js | ||
// Add the new comment to the post and save it | ||
post.get("comments").addObject(comment); | ||
## Using EmberFire Without Ember CLI | ||
// Saving the post will save the embedded comments | ||
post.save(); | ||
``` | ||
EmberFire also works without ember-cli. See the [Firebase documentation](https://firebase.com/docs/web/libraries/ember/guide.html#section-without-ember-cli) for instructions on getting started. | ||
##### `belongsTo()` | ||
## Contributing to EmberFire | ||
Any embedded `belongsTo()` relationship must specify an `id` property in the payload: | ||
If you'd like to contribute to EmberFire, run the following commands to get your environment set up: | ||
```json | ||
{ | ||
"posts": { | ||
"post_id_1": { | ||
"user": { | ||
"id": "myusername" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
## Contributing | ||
If you'd like to contribute to EmberFire, you'll need to run the following commands to get your | ||
environment set up: | ||
### Installation | ||
* `git clone` this repository | ||
* `npm install -g ember-cli bower` | ||
* `npm install` | ||
@@ -260,0 +54,0 @@ * `bower install` |
@@ -11,3 +11,3 @@ import Ember from 'ember'; | ||
* | ||
* EmberFire 1.4.1 | ||
* EmberFire 1.4.2 | ||
* https://github.com/firebase/emberfire/ | ||
@@ -14,0 +14,0 @@ * License: MIT |
Sorry, the diff of this file is not supported yet
259014
67