Commit 9642105bd047078b96b5d68874a78e1c620077e2
use lodash instead of ramda
use `babel-plugin-lodash` to minimize browser builds close https://github.com/enspiral-craftworks/business-stack/issues/11Michael Williams committed on 1/9/2016, 9:45:56 AM
Parent: cba37e3aa847ed827876500c888d0c240f7b3f31
Files changed
.babelrc | changed |
README.md | changed |
app/api.js | changed |
app/reducer.js | changed |
app/routes.js | changed |
app/service.js | changed |
app/todos/containers/index.js | changed |
features/support/hooks.js | changed |
package.json | changed |
.babelrc | ||
---|---|---|
@@ -5,9 +5,10 @@ | ||
5 | 5 | ], |
6 | 6 | "plugins": [ |
7 | 7 | "transform-runtime", |
8 | 8 | "transform-object-rest-spread", |
9 | - "transform-class-properties" | |
9 | + "transform-class-properties", | |
10 | + "lodash" | |
10 | 11 | ], |
11 | 12 | "env": { |
12 | 13 | "hot": { |
13 | 14 | "plugins": [ |
README.md | ||
---|---|---|
@@ -11,9 +11,9 @@ | ||
11 | 11 | - es6/jsx transform: [babelify](https://www.npmjs.com/package/babelify) |
12 | 12 | - css transform: [cssify](https://www.npmjs.com/package/cssify) and [css-modules-require-hook](https://www.npmjs.com/package/css-modules-require-hook) |
13 | 13 | - bulk require: [bulkify](https://www.npmjs.org/package/bulkify) |
14 | 14 | - configuration: [simple-rc](https://www.npmjs.org/package/simple-rc) |
15 | -- utility functions: [ramda](http://ramdajs.com/docs/) | |
15 | +- utility functions: [lodash](https://lodash.com/docs/) | |
16 | 16 | - data model: [tcomb](https://github.com/gcanti/tcomb) |
17 | 17 | - database: [knex](https://www.npmjs.com/package/knex) |
18 | 18 | - api service: [feathers-knex](https://www.npmjs.com/package/feathers-knex) |
19 | 19 | - api validator: [feathers-tcomb](https://www.npmjs.com/package/feathers-tcomb) |
app/api.js | ||
---|---|---|
@@ -4,35 +4,42 @@ | ||
4 | 4 | import hooks from 'feathers-hooks' |
5 | 5 | import rest from 'feathers-rest' |
6 | 6 | import bodyParser from 'body-parser' |
7 | 7 | import cors from 'cors' |
8 | -import { map, mapObjIndexed, reduce, toPairs } from 'ramda' | |
8 | +import { mapValues, forEach, assign, reduce } from 'lodash' | |
9 | 9 | |
10 | -const services = Object.assign( | |
11 | - map( | |
12 | - (module) => module.service.default, | |
13 | - bulk(__dirname, '*/service.js') | |
10 | +const services = assign( | |
11 | + mapValues( | |
12 | + bulk(__dirname, '*/service.js'), | |
13 | + (module) => module.service.default | |
14 | 14 | ), |
15 | - map( | |
16 | - (module) => module.services.map(m => m.default), | |
17 | - bulk(__dirname, '*/services/*.js') | |
15 | + reduce( | |
16 | + bulk(__dirname, '*/services/*.js'), | |
17 | + (sofar, module) => assign( | |
18 | + sofar, | |
19 | + mapValues( | |
20 | + module.services, | |
21 | + m => m.default | |
22 | + ) | |
23 | + ), | |
24 | + {} | |
18 | 25 | ) |
19 | 26 | ) |
20 | 27 | |
21 | 28 | export function createServer (config) { |
22 | - const server = Server() | |
29 | + const app = Server() | |
23 | 30 | .use(cors()) |
24 | 31 | .configure(rest()) |
25 | 32 | .use(bodyParser.json()) |
26 | 33 | .use(bodyParser.urlencoded({ extended: true })) |
27 | 34 | .configure(hooks()) |
28 | 35 | |
29 | - useAll(server, services) | |
36 | + useAll(app, services) | |
30 | 37 | |
31 | - return http.createServer(server) | |
38 | + return http.createServer(app) | |
32 | 39 | } |
33 | 40 | |
34 | 41 | function useAll (app, services) { |
35 | - return reduce((app, [name, service]) => { | |
36 | - return app.use(`/${name}`, service) | |
37 | - }, app, toPairs(services)) | |
42 | + forEach(services, (service, name) => { | |
43 | + app.use(`/${name}`, service) | |
44 | + }) | |
38 | 45 | } |
app/reducer.js | ||
---|---|---|
@@ -1,18 +1,32 @@ | ||
1 | 1 | const bulk = require('bulk-require') |
2 | 2 | import { combineReducers } from 'redux' |
3 | 3 | import { routeReducer } from 'redux-simple-router' |
4 | -import { map } from 'ramda' | |
4 | +import { map, mapValues, assign, camelCase, mapKeys } from 'lodash' | |
5 | 5 | |
6 | -export default combineReducers({ | |
7 | - ...map( | |
8 | - (module) => module.reducer.default, | |
9 | - bulk(__dirname, '*/reducer.js') | |
6 | +export default combine(assign( | |
7 | + mapValues( | |
8 | + bulk(__dirname, '*/reducer.js'), | |
9 | + (module) => module.reducer.default | |
10 | 10 | ), |
11 | - ...map( | |
12 | - (module) => combineReducers( | |
13 | - module.reducers.map(m => m.default) | |
14 | - ), | |
15 | - bulk(__dirname, '*/reducers/*.js') | |
11 | + mapValues( | |
12 | + bulk(__dirname, '*/reducers/*.js'), | |
13 | + (module) => combine( | |
14 | + mapValues( | |
15 | + module.reducers, | |
16 | + m => m.default | |
17 | + ) | |
18 | + ) | |
16 | 19 | ), |
17 | - routing: routeReducer | |
18 | -}) | |
20 | + { | |
21 | + routing: routeReducer | |
22 | + } | |
23 | +)) | |
24 | + | |
25 | +function combine (reducers) { | |
26 | + return combineReducers( | |
27 | + mapKeys( | |
28 | + reducers, | |
29 | + (reducer, name) => camelCase(name) | |
30 | + ) | |
31 | + ) | |
32 | +} |
app/routes.js | ||
---|---|---|
@@ -1,22 +1,22 @@ | ||
1 | 1 | const bulk = require('bulk-require') |
2 | 2 | import React from 'react' |
3 | 3 | import { Route, IndexRoute } from 'react-router' |
4 | -import { mapObjIndexed, values } from 'ramda' | |
4 | +import { map } from 'lodash' | |
5 | 5 | |
6 | 6 | import LayoutContainer from 'app/layout/container' |
7 | 7 | import FourOhFourRoutes from 'app/four-oh-four/routes' |
8 | 8 | |
9 | 9 | export default ( |
10 | 10 | <Route path='/' component={LayoutContainer}> |
11 | 11 | { |
12 | - values(mapObjIndexed( | |
12 | + map( | |
13 | + bulk(__dirname, '!(four-oh-four)/routes.js'), | |
13 | 14 | (module, moduleName) => ({ |
14 | 15 | ...module.routes.default, |
15 | 16 | key: moduleName |
16 | - }), | |
17 | - bulk(__dirname, '!(four-oh-four)/routes.js') | |
18 | - )) | |
17 | + }) | |
18 | + ) | |
19 | 19 | } |
20 | 20 | { FourOhFourRoutes } |
21 | 21 | </Route> |
22 | 22 | ) |
app/service.js | ||
---|---|---|
@@ -1,13 +1,16 @@ | ||
1 | 1 | import knexService from 'feathers-knex' |
2 | 2 | import memoryService from 'feathers-memory' |
3 | +import { assign } from 'lodash' | |
3 | 4 | |
4 | 5 | function dbService (options) { |
5 | - var db = require('app/db') | |
6 | + var db = require('app/db').default | |
6 | 7 | |
7 | - return Object.assign(options, { | |
8 | - Model: db | |
9 | - }) | |
8 | + return knexService( | |
9 | + assign(options, { | |
10 | + Model: db | |
11 | + }) | |
12 | + ) | |
10 | 13 | } |
11 | 14 | |
12 | 15 | export default process.env.NODE_ENV === 'test' ? |
13 | 16 | memoryService : |
app/todos/containers/index.js | ||
---|---|---|
@@ -1,7 +1,7 @@ | ||
1 | 1 | import React from 'react' |
2 | 2 | import { connect } from 'react-redux' |
3 | -import { map, values } from 'ramda' | |
3 | +import { map } from 'lodash' | |
4 | 4 | |
5 | 5 | import actions from '../actions' |
6 | 6 | import TodoList from '../components/todo-list' |
7 | 7 | import Todo from '../components/todo' |
@@ -13,11 +13,11 @@ | ||
13 | 13 | |
14 | 14 | render () { |
15 | 15 | return <TodoList> |
16 | 16 | { |
17 | - values(map(todo => { | |
17 | + map(this.props.todos, todo => { | |
18 | 18 | return <Todo todo={todo} /> |
19 | - }, this.props.todos)) | |
19 | + }) | |
20 | 20 | } |
21 | 21 | </TodoList> |
22 | 22 | } |
23 | 23 | } |
features/support/hooks.js | ||
---|---|---|
@@ -1,39 +1,39 @@ | ||
1 | 1 | require('babel-core/register') |
2 | 2 | require('css-modules-require-hook') |
3 | 3 | |
4 | -const R = require('ramda') | |
4 | +const _ = require('lodash') | |
5 | 5 | const parallel = require('run-parallel') |
6 | 6 | |
7 | 7 | const config = require('app/config') |
8 | 8 | |
9 | 9 | module.exports = function () { |
10 | - const servers = R.map(function (module) { | |
11 | - return module.createServer(config) | |
12 | - }, { | |
10 | + const servers = _.mapValues({ | |
13 | 11 | static: require('app/static'), |
14 | 12 | api: require('app/api'), |
15 | 13 | render: require('app/render') |
14 | + }, function (module) { | |
15 | + return module.createServer(config) | |
16 | 16 | }) |
17 | 17 | |
18 | 18 | function start (cb) { |
19 | 19 | parallel( |
20 | - R.values(R.mapObjIndexed(function (server, name) { | |
20 | + _.map(servers, function (server, name) { | |
21 | 21 | return function (callback) { |
22 | 22 | server.listen(config[name].url.port, callback) |
23 | 23 | } |
24 | - }, servers)), | |
24 | + }), | |
25 | 25 | cb |
26 | 26 | ) |
27 | 27 | } |
28 | 28 | |
29 | 29 | function close (cb) { |
30 | 30 | parallel( |
31 | - R.values(R.mapObjIndexed(function (server, name) { | |
31 | + _.map(servers, function (server, name) { | |
32 | 32 | return function (callback) { |
33 | 33 | server.close(callback) |
34 | 34 | } |
35 | - }, servers)), | |
35 | + }), | |
36 | 36 | cb |
37 | 37 | ) |
38 | 38 | } |
39 | 39 |
package.json | ||
---|---|---|
@@ -86,8 +86,9 @@ | ||
86 | 86 | "zombie": "^4.2.1" |
87 | 87 | }, |
88 | 88 | "dependencies": { |
89 | 89 | "babel-core": "^6.2.1", |
90 | + "babel-plugin-lodash": "^1.1.0", | |
90 | 91 | "babel-plugin-transform-class-properties": "^6.3.13", |
91 | 92 | "babel-plugin-transform-object-rest-spread": "^6.1.18", |
92 | 93 | "babel-plugin-transform-runtime": "^6.1.18", |
93 | 94 | "babel-preset-es2015": "^6.1.18", |
@@ -113,13 +114,13 @@ | ||
113 | 114 | "feathers-tcomb": "^1.0.0", |
114 | 115 | "history": "^1.13.1", |
115 | 116 | "isomorphic-fetch": "^2.2.0", |
116 | 117 | "lnfs-cli": "^1.0.1", |
118 | + "lodash": "^3.10.1", | |
117 | 119 | "npm-run-all": "^1.3.2", |
118 | 120 | "pg": "^4.4.3", |
119 | 121 | "pinkie-promise": "^2.0.0", |
120 | 122 | "predirect": "^1.1.0", |
121 | - "ramda": "^0.18.0", | |
122 | 123 | "react": "^0.14.3", |
123 | 124 | "react-dom": "^0.14.3", |
124 | 125 | "react-redux": "^4.0.1", |
125 | 126 | "react-router": "^1.0.0", |
Built with git-ssb-web