git ssb

1+

dinoworm ๐Ÿ› / catstack



Commit 9642105bd047078b96b5d68874a78e1c620077e2

use lodash instead of ramda

use `babel-plugin-lodash` to minimize browser builds

close https://github.com/enspiral-craftworks/business-stack/issues/11
Michael Williams committed on 1/9/2016, 9:45:56 AM
Parent: cba37e3aa847ed827876500c888d0c240f7b3f31

Files changed

.babelrcchanged
README.mdchanged
app/api.jschanged
app/reducer.jschanged
app/routes.jschanged
app/service.jschanged
app/todos/containers/index.jschanged
features/support/hooks.jschanged
package.jsonchanged
.babelrcView
@@ -5,9 +5,10 @@
55 ],
66 "plugins": [
77 "transform-runtime",
88 "transform-object-rest-spread",
9- "transform-class-properties"
9+ "transform-class-properties",
10+ "lodash"
1011 ],
1112 "env": {
1213 "hot": {
1314 "plugins": [
README.mdView
@@ -11,9 +11,9 @@
1111 - es6/jsx transform: [babelify](https://www.npmjs.com/package/babelify)
1212 - css transform: [cssify](https://www.npmjs.com/package/cssify) and [css-modules-require-hook](https://www.npmjs.com/package/css-modules-require-hook)
1313 - bulk require: [bulkify](https://www.npmjs.org/package/bulkify)
1414 - 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/)
1616 - data model: [tcomb](https://github.com/gcanti/tcomb)
1717 - database: [knex](https://www.npmjs.com/package/knex)
1818 - api service: [feathers-knex](https://www.npmjs.com/package/feathers-knex)
1919 - api validator: [feathers-tcomb](https://www.npmjs.com/package/feathers-tcomb)
app/api.jsView
@@ -4,35 +4,42 @@
44 import hooks from 'feathers-hooks'
55 import rest from 'feathers-rest'
66 import bodyParser from 'body-parser'
77 import cors from 'cors'
8-import { map, mapObjIndexed, reduce, toPairs } from 'ramda'
8+import { mapValues, forEach, assign, reduce } from 'lodash'
99
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
1414 ),
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+ {}
1825 )
1926 )
2027
2128 export function createServer (config) {
22- const server = Server()
29+ const app = Server()
2330 .use(cors())
2431 .configure(rest())
2532 .use(bodyParser.json())
2633 .use(bodyParser.urlencoded({ extended: true }))
2734 .configure(hooks())
2835
29- useAll(server, services)
36+ useAll(app, services)
3037
31- return http.createServer(server)
38+ return http.createServer(app)
3239 }
3340
3441 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+ })
3845 }
app/reducer.jsView
@@ -1,18 +1,32 @@
11 const bulk = require('bulk-require')
22 import { combineReducers } from 'redux'
33 import { routeReducer } from 'redux-simple-router'
4-import { map } from 'ramda'
4+import { map, mapValues, assign, camelCase, mapKeys } from 'lodash'
55
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
1010 ),
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+ )
1619 ),
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.jsView
@@ -1,22 +1,22 @@
11 const bulk = require('bulk-require')
22 import React from 'react'
33 import { Route, IndexRoute } from 'react-router'
4-import { mapObjIndexed, values } from 'ramda'
4+import { map } from 'lodash'
55
66 import LayoutContainer from 'app/layout/container'
77 import FourOhFourRoutes from 'app/four-oh-four/routes'
88
99 export default (
1010 <Route path='/' component={LayoutContainer}>
1111 {
12- values(mapObjIndexed(
12+ map(
13+ bulk(__dirname, '!(four-oh-four)/routes.js'),
1314 (module, moduleName) => ({
1415 ...module.routes.default,
1516 key: moduleName
16- }),
17- bulk(__dirname, '!(four-oh-four)/routes.js')
18- ))
17+ })
18+ )
1919 }
2020 { FourOhFourRoutes }
2121 </Route>
2222 )
app/service.jsView
@@ -1,13 +1,16 @@
11 import knexService from 'feathers-knex'
22 import memoryService from 'feathers-memory'
3+import { assign } from 'lodash'
34
45 function dbService (options) {
5- var db = require('app/db')
6+ var db = require('app/db').default
67
7- return Object.assign(options, {
8- Model: db
9- })
8+ return knexService(
9+ assign(options, {
10+ Model: db
11+ })
12+ )
1013 }
1114
1215 export default process.env.NODE_ENV === 'test' ?
1316 memoryService :
app/todos/containers/index.jsView
@@ -1,7 +1,7 @@
11 import React from 'react'
22 import { connect } from 'react-redux'
3-import { map, values } from 'ramda'
3+import { map } from 'lodash'
44
55 import actions from '../actions'
66 import TodoList from '../components/todo-list'
77 import Todo from '../components/todo'
@@ -13,11 +13,11 @@
1313
1414 render () {
1515 return <TodoList>
1616 {
17- values(map(todo => {
17+ map(this.props.todos, todo => {
1818 return <Todo todo={todo} />
19- }, this.props.todos))
19+ })
2020 }
2121 </TodoList>
2222 }
2323 }
features/support/hooks.jsView
@@ -1,39 +1,39 @@
11 require('babel-core/register')
22 require('css-modules-require-hook')
33
4-const R = require('ramda')
4+const _ = require('lodash')
55 const parallel = require('run-parallel')
66
77 const config = require('app/config')
88
99 module.exports = function () {
10- const servers = R.map(function (module) {
11- return module.createServer(config)
12- }, {
10+ const servers = _.mapValues({
1311 static: require('app/static'),
1412 api: require('app/api'),
1513 render: require('app/render')
14+ }, function (module) {
15+ return module.createServer(config)
1616 })
1717
1818 function start (cb) {
1919 parallel(
20- R.values(R.mapObjIndexed(function (server, name) {
20+ _.map(servers, function (server, name) {
2121 return function (callback) {
2222 server.listen(config[name].url.port, callback)
2323 }
24- }, servers)),
24+ }),
2525 cb
2626 )
2727 }
2828
2929 function close (cb) {
3030 parallel(
31- R.values(R.mapObjIndexed(function (server, name) {
31+ _.map(servers, function (server, name) {
3232 return function (callback) {
3333 server.close(callback)
3434 }
35- }, servers)),
35+ }),
3636 cb
3737 )
3838 }
3939
package.jsonView
@@ -86,8 +86,9 @@
8686 "zombie": "^4.2.1"
8787 },
8888 "dependencies": {
8989 "babel-core": "^6.2.1",
90+ "babel-plugin-lodash": "^1.1.0",
9091 "babel-plugin-transform-class-properties": "^6.3.13",
9192 "babel-plugin-transform-object-rest-spread": "^6.1.18",
9293 "babel-plugin-transform-runtime": "^6.1.18",
9394 "babel-preset-es2015": "^6.1.18",
@@ -113,13 +114,13 @@
113114 "feathers-tcomb": "^1.0.0",
114115 "history": "^1.13.1",
115116 "isomorphic-fetch": "^2.2.0",
116117 "lnfs-cli": "^1.0.1",
118+ "lodash": "^3.10.1",
117119 "npm-run-all": "^1.3.2",
118120 "pg": "^4.4.3",
119121 "pinkie-promise": "^2.0.0",
120122 "predirect": "^1.1.0",
121- "ramda": "^0.18.0",
122123 "react": "^0.14.3",
123124 "react-dom": "^0.14.3",
124125 "react-redux": "^4.0.1",
125126 "react-router": "^1.0.0",

Built with git-ssb-web