Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Inside Bdash

Inside Bdash

Kazuhito Hokamura

March 16, 2017
Tweet

More Decks by Kazuhito Hokamura

Other Decks in Technology

Transcript

  1. import { dispatch } from './QueryStore'; import Database from '../lib/Database';

    const QueryAction = {}; QueryAction.addNewQuery = params => { Database.Query.create(params).then(query => { dispatch('addNewQuery', { query }); }); }; Action Creator 㲗 Domain Logic
  2. // Pageͷ੾ସ࣌ʹຖճݺ͹ΕΔAction Creator QueryAction.initialize = () => { Promise.all([ Database.fetchQueries(),

    Database.fetchDataSources() ]).then(([queries, dataSources]) => { dispatch('initialize', { queries, dataSources }); }); }; // Store class QueryStore { reduce(type, { queries, dataSources }) { switch (type) { case 'initialize': { // ߋ৽෼͚ͩϚʔδ͢ΔͷͰ੾ସલͷঢ়ଶ͸อ࣋Ͱ͖Δ return merge(this.state, { queries, dataSources }); } } } }
  3. let state = { todos: [ { id: 1, text:

    'foo' }, { id: 2, text: 'foo' }, ], //... } function updateTodo(state, { id, text }) { return Object.assign({}, state, { todos: state.todos.map(todo => { if (todo.id === id) { return Object.assign({}, todo, { text }); } else { return todo; } }), }); }
  4. import immup from 'immup'; let state = { todos: [

    { id: 1, text: 'foo' }, { id: 2, text: 'foo' }, ], //... } function updateTodo(state, { id, text }) { let index = state.todos.findIndex(todo => todo.id === id ); return immup.set(`todos.${index}.text`, text); }
  5. Storeʹ૊ΈࠐΉ reduce(action, payload) { switch (action) { case 'addNewQuery': {

    return this .set('selectedQueryId', payload.query.id) .set('editor.line', null) .prepend('queries', payload.query); } //... } }