Last active
February 19, 2017 10:02
-
-
Save wooandoo/ebfa40f96ba41659765a09b3715587c1 to your computer and use it in GitHub Desktop.
New 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
import Ember from 'ember'; | |
import hbs from 'htmlbars-inline-precompile'; | |
import connect from 'ember-redux/components/connect'; | |
var stateToComputed = (state, attrs) => { | |
return { | |
}; | |
}; | |
var dispatchToActions = (dispatch) => { | |
return { | |
}; | |
}; | |
const ItemComponent = Ember.Component.extend({ | |
tagName: 'li', | |
redux: Ember.inject.service(), | |
layout: hbs` | |
#{{index}} | |
<input value={{item.name}} oninput={{action 'change'}} /> | |
`, | |
actions: { | |
change(event) { | |
let new_name = event.target.value | |
let index = this.get('index') | |
this.get('redux').dispatch({ | |
type: 'UPDATE', | |
index, | |
name: new_name | |
}) | |
} | |
} | |
}); | |
export default connect(stateToComputed, dispatchToActions)(ItemComponent); |
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 connect from 'ember-redux/components/connect'; | |
var stateToComputed = (state) => { | |
return { | |
list: state.items | |
}; | |
}; | |
var dispatchToActions = (dispatch) => { | |
return { | |
add: () => dispatch({type: 'ADD'}) | |
}; | |
}; | |
const ListComponent = Ember.Component.extend({ | |
layout: hbs` | |
<h1>MY LIST</h1> | |
<p {{action 'add'}}>ADD ITEM</p> | |
<h2>first list of items</h2> | |
<ul> | |
{{#each list key='id' as |item index|}} | |
{{my-item item=item index=index}} | |
{{/each}} | |
</ul> | |
<h2>second list of items</h2> | |
<ul> | |
{{#each list as |item index|}} | |
{{my-item item=item index=index}} | |
{{/each}} | |
</ul> | |
` | |
}); | |
export default connect(stateToComputed, dispatchToActions)(ListComponent); |
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
let items = ((state, action) => { | |
switch (action.type) { | |
case 'ADD': | |
return [ | |
...state, | |
{ | |
id: state.length, | |
name: 'unknown item' | |
} | |
]; | |
break; | |
case 'UPDATE': | |
console.log('UPDATE name: '+action.name); | |
return [ | |
...state.slice(0, action.index), | |
{ | |
...state[action.index], | |
name: action.name | |
}, | |
...state.slice(action.index +1) | |
]; | |
break; | |
default: | |
return state || []; | |
break; | |
} | |
}); | |
export default { | |
items | |
} |
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.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": { | |
"ember-redux": "2.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment