Created
March 13, 2017 04:01
-
-
Save pswai/d7b42d2c6d480dda2972cef08563b4e5 to your computer and use it in GitHub Desktop.
Function-style HOC
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 Foo from './foo-comp'; | |
import decorate from './decorate-hoc'; | |
export default decorate(Foo); |
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 Foo from './foo-comp'; | |
import log from './log-hoc'; | |
export default log('error')(Foo); |
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'; | |
const decorateHoc = Component => { | |
return Component.extend({ | |
actions: { | |
handleButtonClick(text) { | |
this._super(`Decorated: ${text}`); | |
} | |
} | |
}); | |
}; | |
export default decorateHoc; |
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.Component.extend({ | |
classNames: ['foo'], | |
// This is important. Without this Ember won't pick up the right template | |
layoutName: 'components/foo-comp', | |
text: 'foo', | |
onSomethingClick: Ember.K, | |
actions: { | |
handleButtonClick(text) { | |
this.get('onSomethingClick')(`Clicked button in ${text}`); | |
}, | |
handleTextClick(text) { | |
this.get('onSomethingClick')(`Clicked text in ${text}`); | |
} | |
} | |
}); |
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'; | |
const logHoc = logLevel => Component => Component.extend({ | |
actions: { | |
handleButtonClick(text) { | |
console[logLevel](`Passed in ${text}`); | |
this._super(...arguments); | |
} | |
} | |
}); | |
export default logHoc; |
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({ | |
echoText: 'Click on the texts or the buttons to start', | |
actions: { | |
echo(text) { | |
this.set('echoText', text); | |
} | |
} | |
}); |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.foo { | |
border: 1px solid lightgray; | |
padding: 10px; | |
margin-top: 10px; | |
} |
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.11.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.11.0", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.11.0", | |
"ember-testing": "2.11.0" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment