Last active
July 11, 2017 06:53
-
-
Save sukima/bb343cb1e1f20c707cf5aaf36d8b06ab to your computer and use it in GitHub Desktop.
Simple Decorator Pattern
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'; | |
import MyModelDecorator from '../decorators/my-model'; | |
export default Ember.Component.extend({ | |
decoratedPerson: Ember.computed('person', { | |
get() { | |
// If you needed dependency injection you would need to | |
// let MyModelDecorator = Ember.getOwner(this).factoryFor('decorator:my-model'); | |
// OR | |
// let MyModelDecorator = Ember.getOwner(this)._lookupFactory('decorator:my-model'); | |
// Depending on your version of Ember. | |
return MyModelDecorator.create({content: this.get('person')}); | |
} | |
}) | |
}); |
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({ | |
model: Ember.computed({ | |
get() { | |
return this.get('store').createRecord('my-model', { | |
firstName: 'Bob', | |
lastName: 'NoName' | |
}); | |
} | |
}) | |
}); |
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.ObjectProxy.extend({ | |
isAwesome: Ember.computed.equal('content.firstName', 'Jane'), | |
awesomeStyle: Ember.computed('isAwesome', { | |
get() { | |
let style = this.get('isAwesome') ? 'background-color: gold;' : ''; | |
return Ember.String.htmlSafe(style); | |
} | |
}) | |
}); |
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"; | |
export default Model.extend({ | |
firstName: attr('string'), | |
lastName: attr('string') | |
}); |
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.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment