Last active
June 14, 2017 09:58
-
-
Save chris-kobrzak/1acd4b9a46c56337f23ed6bccbec93f4 to your computer and use it in GitHub Desktop.
[WIP] Use ES6 classes instead of object literals in Ember.js
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
export default function buildObjectFromClass (className) { | |
return Object.getOwnPropertyNames(className.prototype) | |
.filter(propertyName => propertyName != 'constructor') | |
.reduce((result, propertyName) => { | |
result[propertyName] = className.prototype[propertyName] | |
return result | |
}, {}) | |
} |
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
export default function buildObjectFromInstance (instance) { | |
return Object.getOwnPropertyNames(instance) | |
.reduce((result, propertyName) => { | |
result[propertyName] = instance[propertyName] | |
return result | |
}, {}) | |
} |
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 buildObjectFromInstance from '../utils/build-object-from-instance' | |
class Scientists { | |
constructor () { | |
this.nameFormat = 'full' | |
} | |
} | |
const scientists = new Scientists() | |
const scientistsObjectLiteral = buildObjectFromInstance(scientists) | |
export default Ember.Controller.extend(scientistsObjectLiteral) |
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 buildObjectFromClass from '../utils/build-object-from-class' | |
class Scientists { | |
model () { | |
return ['Marie Curie', 'Mae Jemison', 'Albert Hofmann'] | |
} | |
} | |
const scientistsObjectLiteral = buildObjectFromClass(Scientists) | |
export default Ember.Route.extend(scientistsObjectLiteral) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment