Last active
May 9, 2017 15:54
-
-
Save runspired/c92c8d066511083f8c171a33ae27dedf to your computer and use it in GitHub Desktop.
Can we unload a record that has been deleted?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let IS_DELETED = false; | |
export default class Adapter { | |
queryRecord() { | |
let isDeleted = IS_DELETED; | |
IS_DELETED = true; | |
return Promise.resolve({ | |
data: { | |
type: 'api-managed', | |
id: '1', | |
attributes: { | |
isDeleted | |
} | |
} | |
}); | |
} | |
get() { | |
return null; | |
} | |
static create() { | |
return new Adapter(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
hasUpdatedDeletedRecord: false, | |
actions: { | |
updateRecord() { | |
let isDeleted = this.get('record.isDeleted'); | |
this.set('hasUpdatedDeletedRecord', isDeleted); | |
this.get('store').queryRecord('api-managed', {}); | |
}, | |
unloadRecord() { | |
let record = this.get('record.content'); | |
this.set('record', null); | |
record.unloadRecord(); | |
} | |
}, | |
init() { | |
this._super(); | |
this.record = this.get('store').queryRecord('api-managed', {}); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
export default Model.extend({ | |
isDeleted: attr() | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Serializer { | |
normalizeResponse(_, __, data) { | |
return data; | |
} | |
static create() { | |
return new Serializer(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "~2.13.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment