Last active
January 13, 2018 02:07
-
-
Save gabrielgrant/0f0bf0fd1428cbd76f40a0d9910331d3 to your computer and use it in GitHub Desktop.
Recursive render
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.Component.extend({ | |
}); |
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({ | |
appName: 'Ember Twiddle', | |
resetHistory: function() { | |
this.set('history', []); | |
}.on('init'), | |
actions: { | |
addChild() { | |
let oldModel = this.get('model'); | |
this.get('history').pushObject(oldModel); | |
//let newModel = JSON.parse(JSON.stringify(oldModel)); | |
let newModel = Ember.copy(oldModel, true); | |
newModel.children.push({name: 'new child', children:[]}); | |
console.log(oldModel, newModel) | |
this.set('model', newModel); | |
}, | |
restructureChildren() { | |
let oldModel = this.get('model'); | |
this.get('history').pushObject(oldModel); | |
//let newModel = JSON.parse(JSON.stringify(oldModel)); | |
let newModel = Ember.copy(oldModel, true); | |
let secondLastTopLevelChild = newModel.children.slice(-2)[0] | |
secondLastTopLevelChild.children.push(newModel.children.pop()); | |
console.log(oldModel, newModel) | |
this.set('model', newModel); | |
}, | |
undo() { | |
this.set('model', this.get('history').popObject()); | |
} | |
} | |
}); |
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.Route.extend({ | |
model() { | |
return { | |
name: 'parent', | |
children: [ | |
{ | |
name: 'child 1', | |
children: [] | |
}, | |
{ | |
name: 'child 2', | |
children: [] | |
} | |
] | |
}; | |
} | |
}); |
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.13.0", | |
"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.16.2", | |
"ember-template-compiler": "2.16.2", | |
"ember-testing": "2.16.2" | |
}, | |
"addons": { | |
"ember-data": "2.16.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment