Created
February 19, 2017 09:28
-
-
Save wooandoo/6ea6f537b666a300c0b30ef0fa51bec3 to your computer and use it in GitHub Desktop.
New Twiddle
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 hbs from 'htmlbars-inline-precompile'; | |
import connect from 'ember-redux/components/connect'; | |
var stateToComputed = (state) => { | |
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 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 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</p> | |
<ul> | |
{{#each list as |item index|}} | |
{{my-item item=item index=index}} | |
{{/each}} | |
</ul> | |
<h2>shadow 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 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'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
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
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 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
{ | |
"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