Last active
June 22, 2017 08:23
-
-
Save msalahz/055abd747761d16d70b8d69827b0b9f7 to your computer and use it in GitHub Desktop.
ember-redux
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 hbs from "htmlbars-inline-precompile"; | |
import Redux from 'redux'; | |
const { createStore } = Redux; | |
const reducer = (state, action) => { console.log(state, action); | |
if(action.type === 'ADD'){ | |
return Object.assign({}, state, {number: state.number + 1}); | |
} | |
return state || { id: 1, number: 1 } | |
} | |
const store = createStore(reducer); | |
export default Ember.Component.extend({ | |
init(){ | |
this._super(...arguments); | |
store.subscribe(() =>{ | |
this.notifyPropertyChange('number'); | |
}); | |
}, | |
number: Ember.computed(function() { | |
return store.getState()['number']; | |
}), | |
actions:{ | |
add(){ | |
store.dispatch({type: 'ADD'}); | |
} | |
}, | |
layout: hbs` | |
<h2> Number: {{number}}</h2> | |
<button onclick={{action "add"}}>Add</button> | |
` | |
}); |
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({ | |
appName: 'Ember Twiddle' | |
}); |
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", | |
"ember-redux": "2.9.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment