Last active
September 13, 2018 11:24
-
-
Save toranb/c6bebdbe5964c89598bea2761197e232 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
export const updateItem = (id, name) => dispatch => dispatch({type: 'UPDATE_ITEM', id, name}); | |
export const toggleEdit = (id, value) => dispatch => dispatch({type: 'TOGGLE_EDIT', id, value}); |
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.Component.extend({ | |
didReceiveAttrs() { | |
this._super(...arguments); | |
const itemName = this.get('item.name'); | |
this.set('itemName', itemName); | |
} | |
}); |
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.Component.extend({ | |
tagName: 'li' | |
}); |
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 { connect } from 'ember-redux'; | |
import { toggleEdit, updateItem } from '../actions/items'; | |
const ListComponent = Ember.Component.extend({ | |
tagName: 'ul' | |
}); | |
const stateToComputed = state => ({ | |
items: state.items.all, | |
editing: state.items.editing | |
}); | |
const dispatchToActions = { | |
toggleEdit, | |
updateItem | |
}; | |
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.Helper.helper(function(params) { | |
return params[0] === params[1]; | |
}); |
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 { combineReducers } from 'redux' | |
import items from './items' | |
const rootReducer = combineReducers({ | |
items | |
}) | |
export default rootReducer |
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 mapValues from 'lodash/mapValues'; | |
import defaults from 'lodash/defaults'; | |
const initialState = { | |
editing: null, | |
all: { | |
1: { | |
id: 1, | |
name: 'One' | |
}, | |
2: { | |
id: 2, | |
name: 'Two' | |
}, | |
3: { | |
id: 3, | |
name: 'Three' | |
} | |
} | |
}; | |
export default function items(state, action) { | |
switch (action.type) { | |
case 'UPDATE_ITEM': { | |
let items = mapValues(state.all, item => { | |
return item.id === action.id ? defaults({ | |
name: action.name | |
}, item) : item; | |
}); | |
return Object.assign({}, state, { all: items }); | |
} | |
case 'TOGGLE_EDIT': { | |
let editing = !action.value ? null : action.id; | |
return Object.assign({}, state, { editing: editing }); | |
} | |
default: { | |
return state || initialState; | |
} | |
} | |
} |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
ul { list-style-type: none; } |
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.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-redux": "4.0.0", | |
"ember-lodash-es-shim": "1.1.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment