Last active
February 8, 2019 17:53
-
-
Save mrryanjohnston/d35dde9e0ac39ebc5e877168ab63f425 to your computer and use it in GitHub Desktop.
Proxy Array with Record Fadeout
This file contains hidden or 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'; | |
import { copy } from '@ember/object/internals'; | |
import { later } from '@ember/runloop'; | |
import { set } from '@ember/object'; | |
export default Ember.Component.extend({ | |
didReceiveAttrs () { | |
this._super(...arguments); | |
if (!this.recordsProxy) { | |
this.recordsProxy = copy(this.records); | |
return; | |
} | |
let newRecordsProxy = copy(this.recordsProxy); | |
this.records.forEach((record, index) => { | |
if (this.recordsProxy.indexOf(record) === -1) { | |
newRecordsProxy.push(record); | |
} | |
}); | |
this.set('recordsProxy', newRecordsProxy); | |
}, | |
actions: { | |
removeRecord (record) { | |
this.removeRecord(record); | |
set(record, 'deleted', true); | |
later(() => { | |
this.$(`li:contains(${record.id} | Deleted!)`).fadeOut(); | |
let index = this.recordsProxy.indexOf(record); | |
this.recordsProxy.splice(index, 1); | |
}, 3000); | |
} | |
} | |
}); |
This file contains hidden or 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({ | |
init () { | |
this._super(...arguments); | |
this.records = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }] | |
}, | |
nextId: 5, | |
actions: { | |
addRecord () { | |
this.records.addObject({ id: this.nextId++ }); | |
}, | |
addRecordRebuildArray () { | |
this.set('records', [...this.records, { id: this.nextId++ }]); | |
}, | |
removeRecord (record) { | |
this.records.removeObject(record); | |
} | |
} | |
}); |
This file contains hidden or 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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment