Skip to content

Instantly share code, notes, and snippets.

@mnutt
Last active January 30, 2017 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mnutt/0da967c62957768b27df3ce654a727c7 to your computer and use it in GitHub Desktop.
Save mnutt/0da967c62957768b27df3ce654a727c7 to your computer and use it in GitHub Desktop.
DDAU with slow deserializer
import Ember from 'ember';
const { get, computed } = Ember;
function serialize(val) {
return JSON.stringify(val);
}
function deserialize(val) {
console.log('deserializing, this takes a long time...');
return JSON.parse(val);
}
export default Ember.Component.extend({
parsedValue: computed('value', function() {
return deserialize(get(this, 'value'));
}),
actions: {
update() {
let parsedValue = get(this, 'parsedValue');
parsedValue.push(Math.random()+"");
let storedValue = serialize(parsedValue);
get(this, 'onupdate')(storedValue);
}
}
});
import Ember from 'ember';
const { set } = Ember;
export default Ember.Controller.extend({
value: '["hello","there"]',
actions: {
update(value) {
set(this, 'value', value);
}
}
});
<h1>Parser Round Trip Test</h1>
<p>
This test app uses DDAU, but includes an editing component that has a very slow parse/serialize step that we'd like to avoid. Normal DDAU means pushing the serialized value to the parent and then having the component re-parse, how can we avoid the re-parse?
</p>
<p>
{{slow-component value=value onupdate=(action 'update')}}
</p>
<p>
parsed: {{parsedValue}}
</p>
<p>
raw: <pre>{{value}}</pre>
</p>
<p>
<button {{action 'update'}}>update</button>
</p>
{
"version": "0.11.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.10.2",
"ember-data": "2.11.0",
"ember-template-compiler": "2.10.2",
"ember-testing": "2.10.2"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment