![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
build-reducer
Advanced tools
Write Redux reducers with simpler syntax
build-reducer lets you write Redux reducers as individual functions, rather than one huge switch
block.
import buildReducer from 'build-reducer'
import {createStore} from 'redux'
const reducer = buildReducer({
reset () {
return {}
},
'profile:load' (state, {payload}) {
return { ...state, profile: payload }
},
'profile:reset' (state, action) {
return { ...state, profile: {} }
}
})
let store = createStore(reducer)
/* Traditional Redux reducer without build-reducer */
function reducer (state, action) {
switch (action.type) {
case 'reset':
return {}
case 'profile:load':
return { ...state, profile: action.payload }
case 'profile:reset':
return { ...state, profile: {} }
default:
return state
}
}
let store = createStore(reducer)
npm install --save build-reducer
build-reducer is available via npm.
var buildReducer = require('build-reducer') // ES5
import buildReducer from 'build-reducer' // ES2015+
buildReducer(reducer, [defaultState])
Creates a function that calls methods from reducer
based on the given action type.
defaultState
is optional; if given, it will be used as the state if the state is currently undefined
.
const reducer = buildReducer({
'reset':
() => {}
'profile:load':
(state, {payload}) => ({ ...state, profile: payload })
'profile:reset':
(state, action) => ({ ...state, profile: {} })
})
const RESET = 'RESET'
const LOAD_PROFILE = 'LOAD_PROFILE'
const RESET_PROFILE = 'RESET_PROFILE'
const reducer = buildReducer({
[RESET] () {
return {}
},
[LOAD_PROFILE] (state, {payload}) {
return { ...state, profile: payload }
},
[RESET_PROFILE] (state, action) {
return { ...state, profile: {} }
}
})
const reducer = buildReducer({
'reset': function () {
return {}
},
'profile:load': function (state, action) {
return Object.assign({}, state, { profile: action.payload })
},
'profile:reset': function (state, action) {
return Object.assign({}, state, { profile: {} })
}
})
build-reducer © 2016+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors (list).
ricostacruz.com · GitHub @rstacruz · Twitter @rstacruz
[v1.2.0]
Aug 24, 2016
FAQs
Write Redux reducers with simpler syntax
The npm package build-reducer receives a total of 0 weekly downloads. As such, build-reducer popularity was classified as not popular.
We found that build-reducer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.