All files / src index.js

60.87% Statements 14/23
100% Branches 0/0
30.77% Functions 4/13
76.47% Lines 13/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79                      3x             22x                 9x 9x 9x 9x 9x 9x 9x 9x       9x                                                     3x                       3x  
import React from 'react'
import _ from 'lodash'
import 'whatwg-fetch'
 
import ApiAdapter from './adapter/ApiAdapter'
import RequestAdapter from './adapter/RequestAdapter'
 
import _createReducer from './createReducer'
import Model from './model'
import pagingHoc from './hoc/paging'
 
export const DEFAULT_CONFIG = {
  models: [],
  globalOptions: {
    params: null,
    headers: null,
    body: null
  },
  rootSelector: (state) => state.rest
}
 
 
export default class Wrapper {
  config
  reducer
  middleware
  constructor(_config) {
    this.config = _.merge({}, DEFAULT_CONFIG, _config)
    const { models } = this.config
    console.log('config set: ', this.config)
    this.reducer = _createReducer(models)
    this.middleware = store => next => action => next(action)
    const apiAdapter = new ApiAdapter(this.config)
    const requestAdapter = new RequestAdapter(this.config)
    this._models = _.keyBy(_.map(models, model => new Model(model, this.config, apiAdapter, requestAdapter)), 'modelName')
  }
 
  get(modelName) {
    return this._models[modelName]
  }
 
  updateGlobal(options) {
    _.merge(this.config.globalOptions, options)
  }
 
  clear(dispatch) {
    _.each(this._models, model => dispatch(model.actions.clear()))
  }
 
  // createModelWrapper(model) {
  //   const modelWrapper =
  //    {
  //     modelName: model.modelName,
  //     actions: new ModelActions(model, this.config, this.apiAdapter),
  //     selectors: modelSelectors(model, this.config.rootSelector),
  //     createList: name => {
  //       return {
  //         name: name,
  //         actions: new ListActions()
  //       }
  //     }
  //   }
  // }
}
 
export const connectModel = (model, filter) => (Component) => {
  //const actions = createActions(model)
  // QUESTION:?? Get filtered action here const instances = actions.find()
  return class ModelComponent extends React.Component {
    render() {
      return <Component {...this.props} />
      // restActions={actions}
    }
  }
}
 
 
export const paging = pagingHoc