Skip to content

Instantly share code, notes, and snippets.

@AmilKey
Last active March 2, 2018 18:35
Show Gist options
  • Save AmilKey/56b021df6dff9d8b946a0737a7e76bae to your computer and use it in GitHub Desktop.
Save AmilKey/56b021df6dff9d8b946a0737a7e76bae to your computer and use it in GitHub Desktop.
test push nodes
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this._super(...arguments);
let data = [];
let included = [];
let time = performance.now();
for (let i = 0; i < 50000; i=i+8) {
data.push({
id: i,
type: 'node',
attributes: {
name: `level ${i}`
},
relationships: {
children: {
data: [{id: i+1, type: 'node'}]
}
}
});
included.push(...[{
id: i+1,
type: 'node',
attributes: {
name: `level ${i+1}`
},
relationships: {
children: {
data: [{id: i+2, type: 'node'}, {id: i+3, type: 'node'}]
}
}
},{
id: i+2,
type: 'node',
attributes: {
name: `level ${i+2}`
},
relationships: {
children: {
data: [{id: i+4, type: 'node'}]
}
}
},{
id: i+3,
type: 'node',
attributes: {
name: `level ${i+2}`
}
},{
id: i+4,
type: 'node',
attributes: {
name: `level ${i+3}`
},
relationships: {
children: {
data: [{id: i+5, type: 'node'}, {id: i+6, type: 'node'}]
}
}
},{
id: i+5,
type: 'node',
attributes: {
name: `level ${i+4}`
}
},{
id: i+6,
type: 'node',
attributes: {
name: `level ${i+4}`
}
}]
)
}
const model = this.store.push({data, included});
this.set('time', performance.now() - time);
this.set('model', model);
}
});
import Model from "ember-data/model";
import attr from "ember-data/attr";
import { belongsTo, hasMany } from "ember-data/relationships";
export default Model.extend({
name: attr('string'),
children: hasMany('node', { async: false, inverse: null })
});
{{outlet}}
<h2>Building time - {{time}}ms</h2>
<ul>
{{#each model as |node|}}
<li>{{node.name}}</li>
<ul>
{{#each node.children as |children|}}
<li>{{children.name}}</li>
<ul>
{{#each children.children as |childrenChildren|}}
<li>{{childrenChildren.name}}</li>
<ul>
{{#each childrenChildren.children as |childrenChildrenChildren|}}
<li>{{childrenChildrenChildren.name}}</li>
<ul>
{{#each childrenChildrenChildren.children as |childrenChildrenChildrenChildren|}}
<li>{{childrenChildrenChildrenChildren.name}}</li>
{{/each}}
</ul>
{{/each}}
</ul>
{{/each}}
</ul>
{{/each}}
</ul>
{{/each}}
</ul>
{
"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