@@ -2561,31 +2561,22 @@ module.exports = digest;
25612561var errorPrefix = 'DS.eject(resourceName, id): ' ;
25622562
25632563function _eject ( definition , resource , id ) {
2564- if ( id ) {
2565- var found = false ;
2566- for ( var i = 0 ; i < resource . collection . length ; i ++ ) {
2567- if ( resource . collection [ i ] [ definition . idAttribute ] == id ) {
2568- found = true ;
2569- break ;
2570- }
2571- }
2572- if ( found ) {
2573- resource . collection . splice ( i , 1 ) ;
2574- resource . observers [ id ] . close ( ) ;
2575- delete resource . observers [ id ] ;
2576- delete resource . index [ id ] ;
2577- delete resource . changes [ id ] ;
2578- delete resource . previousAttributes [ id ] ;
2579- delete resource . modified [ id ] ;
2580- delete resource . saved [ id ] ;
2564+ var found = false ;
2565+ for ( var i = 0 ; i < resource . collection . length ; i ++ ) {
2566+ if ( resource . collection [ i ] [ definition . idAttribute ] == id ) {
2567+ found = true ;
2568+ break ;
25812569 }
2582- } else {
2583- resource . collection = [ ] ;
2584- resource . index = { } ;
2585- resource . modified = { } ;
2586- resource . saved = { } ;
2587- resource . changes = { } ;
2588- resource . previousAttributes = { } ;
2570+ }
2571+ if ( found ) {
2572+ resource . collection . splice ( i , 1 ) ;
2573+ resource . observers [ id ] . close ( ) ;
2574+ delete resource . observers [ id ] ;
2575+ delete resource . index [ id ] ;
2576+ delete resource . changes [ id ] ;
2577+ delete resource . previousAttributes [ id ] ;
2578+ delete resource . modified [ id ] ;
2579+ delete resource . saved [ id ] ;
25892580 }
25902581}
25912582
@@ -2594,16 +2585,15 @@ function _eject(definition, resource, id) {
25942585 * @id DS.sync_methods:eject
25952586 * @name eject
25962587 * @description
2597- * Eject the item of the specified type that has the given primary key from the data store. If no primary key is
2598- * provided, eject all items of the specified type from the data store. Ejection only removes items from the data store
2599- * and does not attempt to delete items on the server.
2588+ * Eject the item of the specified type that has the given primary key from the data store. Ejection only removes items
2589+ * from the data store and does not attempt to delete items on the server.
26002590 *
26012591 * ## Signature:
26022592 * ```js
26032593 * DS.eject(resourceName[, id])
26042594 * ```
26052595 *
2606- * ## Examples :
2596+ * ## Example :
26072597 *
26082598 * ```js
26092599 * DS.get('document', 45); // { title: 'How to Cook', id: 45 }
@@ -2613,29 +2603,19 @@ function _eject(definition, resource, id) {
26132603 * DS.get('document', 45); // undefined
26142604 * ```
26152605 *
2616- * Eject all items of the specified type from the data store.
2617- *
2618- * ```js
2619- * DS.filter('document'); // [ { title: 'How to Cook', id: 45 }, { title: 'How to Eat', id: 46 } ]
2620- *
2621- * DS.eject('document');
2622- *
2623- * DS.filter('document'); // [ ]
2624- * ```
2625- *
26262606 * ## Throws
26272607 *
26282608 * - `{IllegalArgumentError}`
26292609 * - `{RuntimeError}`
26302610 * - `{UnhandledError}`
26312611 *
26322612 * @param {string } resourceName The resource type, e.g. 'user', 'comment', etc.
2633- * @param {string|number= } id The primary key of the item to eject.
2613+ * @param {string|number } id The primary key of the item to eject.
26342614 */
26352615function eject ( resourceName , id ) {
26362616 if ( ! this . definitions [ resourceName ] ) {
26372617 throw new this . errors . RuntimeError ( errorPrefix + resourceName + ' is not a registered resource!' ) ;
2638- } else if ( id && ! this . utils . isString ( id ) && ! this . utils . isNumber ( id ) ) {
2618+ } else if ( ! this . utils . isString ( id ) && ! this . utils . isNumber ( id ) ) {
26392619 throw new this . errors . IllegalArgumentError ( errorPrefix + 'id: Must be a string or a number!' , { id : { actual : typeof id , expected : 'string|number' } } ) ;
26402620 }
26412621
@@ -2662,14 +2642,15 @@ module.exports = eject;
26622642} , { } ] , 40 :[ function ( require , module , exports ) {
26632643var errorPrefix = 'DS.ejectAll(resourceName[, params]): ' ;
26642644
2665- function _ejectAll ( definition , params ) {
2666- params . query = params . query || { } ;
2667-
2668- var items = this . filter ( definition . name , params ) ;
2645+ function _ejectAll ( definition , resource , params ) {
2646+ var queryHash = this . utils . toJson ( params ) ,
2647+ items = this . filter ( definition . name , params ) ;
26692648
26702649 for ( var i = 0 ; i < items . length ; i ++ ) {
26712650 this . eject ( definition . name , items [ i ] [ definition . idAttribute ] ) ;
26722651 }
2652+
2653+ delete resource . completedQueries [ queryHash ] ;
26732654}
26742655
26752656/**
@@ -2748,11 +2729,11 @@ function ejectAll(resourceName, params) {
27482729 try {
27492730 if ( ! this . $rootScope . $$phase ) {
27502731 this . $rootScope . $apply ( function ( ) {
2751- _ejectAll . apply ( _this , [ _this . definitions [ resourceName ] , params ] ) ;
2732+ _ejectAll . apply ( _this , [ _this . definitions [ resourceName ] , resource , params ] ) ;
27522733 resource . collectionModified = _this . utils . updateTimestamp ( resource . collectionModified ) ;
27532734 } ) ;
27542735 } else {
2755- _ejectAll . apply ( _this , [ _this . definitions [ resourceName ] , params ] ) ;
2736+ _ejectAll . apply ( _this , [ _this . definitions [ resourceName ] , resource , params ] ) ;
27562737 resource . collectionModified = this . utils . updateTimestamp ( resource . collectionModified ) ;
27572738 }
27582739 } catch ( err ) {
0 commit comments