unirakun / k-redux-factory Goto Github PK
View Code? Open in Web Editor NEWFactory of Redux reducers and their associated actions and selectors.
License: MIT License
Factory of Redux reducers and their associated actions and selectors.
License: MIT License
Hello,
I would like to migrate from 5.0.2 to 6.0 but I have this error when I define a middleware with helper mapPayload. This middleware worked with v5.0.2. Please help me :) because I would like to migrate for reduce my bundle.
Thanks.
Error :
Example :
import { combineReducers } from 'redux'
import { keyValue, simple } from 'k-redux-factory'
import { mapPayload } from 'k-redux-factory/helpers'
const path = 'data.analyse'
const mapCity = city => ({
text: city.label,
...city,
})
const mapCities = cities => cities.map(mapCity)
const middlewares = {
pre: [
mapPayload(/@@krf\/SET>DATA.ANALYSE>CITIES/)(mapCities),
],
}
export const cities = keyValue(middlewares)({ path, key: 'value', name: 'cities', prefix: path, defaultData: [] })
export const establishments = keyValue({ path, key: 'id', name: 'establishments', prefix: path })
export const firstActs = keyValue({ path, key: 'value', name: 'firstActs', prefix: path })
export const hasConsented = simple.bool({ path, name: 'hasConsented', defaultData: false, prefix: path })
export const hasDevisChirurgie = simple.bool({ path, name: 'hasDevisChirurgie', defaultData: false, prefix: path })
export const modeConnecte = simple.bool({ path, name: 'modeConnecte', defaultData: false, prefix: path })
export const result = simple.object({ path, name: 'result', prefix: path })
export const secondActs = keyValue({ path, key: 'value', name: 'secondActs', prefix: path })
export default combineReducers({
cities,
establishments,
firstActs,
hasConsented,
hasDevisChirurgie,
modeConnecte,
result,
secondActs,
})
Right now we can remove instance from keyValue
per their key
.
Add the possibility to remove them per reference equality to full instance.
pseudo code:
const = remove = ([object]) => {
if (typeof object === 'object') {
// remove per reference equality
} else {
// remove per id
}
}
rename del
action to remove
What do you think to add the possibility to add defaultValue with the first parameter ?
function | defaultValue |
---|---|
simpleObject() | {} |
simpleObject({ defaultValue: {} }) | {} |
simpleObject({ my: 'object' }) | {} |
simpleObject('string') | 'string' |
simpleObject([1, 2, 3]) | [1, 2, 3] |
The key for a kyeValue
store is very often id
. We can perhaps set this as default key
?
Idea from @BenoitAverty
factory(key)(state)(name)
factory(key, state)(name)
factory(key, state, name)
We often have to update every values in a keyValue
store. But with the current API, it can lead to a huge number of dispatched actions.
I propose to make update
, addOrUpdate
and replace
action polymorphic on their argument, allowing to pass an instance or an array of instances.
import { keyValue } from 'k-redux-factory'
const store = keyValue({ key: 'id' })
store.addOrUpdate([
{ id: 1, value: '1' },
{ id: 2, value: '2' },
{ id: 3, value: '3' },
])
From @bpetetot
The librairy name doesn't speak itself... and is very long.
Does it be better to call it with factory in the lib name, like : redux-factory or trampss-redux-factory ?
Sometimes, accessing an object in the state from a container is quickier to write than using its selector.
I would like to know all the advantages of k-redux-factory selectors over the direct use the state.
0.8.1
to 0.8.2
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
microbundle is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 13 commits.
23e8e62
0.8.2
04f6c72
ignore .idea for @ForsakenHarmony :)
ce1b3df
pin tiny-glob to 0.2.4 while we wait for a fix for terkelg/tiny-glob@cc4a295
0194bce
Merge pull request #254 from developit/0.8.0
5c8f1b5
Delete workspace.xml
1e1c8c8
Delete vcs.xml
6f0923c
Delete modules.xml
5831089
Delete misc.xml
9549804
Delete microbundle.iml
b1cc70e
Delete Project_Default.xml
1d89820
Delete encodings.xml
ceb5f2f
Delete codeStyleConfig.xml
7323175
Delete Project.xml
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
Write to the README that the lib handle the immutability
This is a @bpetetot question.
π if you agree
π if you disagree
I want to remove orderBy:
orderBy
, then add
this is not ordered anymoreWe could maybe add it later with a post middleware
in helpers
.
What are your thoughs ? @guillaumecrespel @EmrysMyrddin @bpetetot
A new markdown that explain what you have to do to go from 5.X.X to 6.X.X
4.1.3
to 4.1.4
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
npm-run-all is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
the property defaultData is ignored with keyValue
I trying to set a simple array or hashmap but it's not working
if I reset my state, state.path.data
will be undefined
Maybe you could add an optional property in the factory to initalize the data :
factory()()()({ name: 'docgen', type: 'uniq', defaultData: {} })
Our reducer should be like that (pseudo code) :
reducer = (state, action) => {
let previous = [state, action]
midlewares.forEach(middleware => middleware(state, action))
}
The lib will add the current reducer as a core
middleware.
The user could add some of middlewares before and after core
one.
With this pattern the user can change
action
before the core
reducer (use case example: generate id #9)Presently, this is boring to have middlewares in first function because 99% of times we don't use it.
So the signature is 99% of times this :
factory(/* middleware */)('id')('a.path')('aname')
How can we simplify that but let the user :
trampss-redux-factory
)From @bpetetot
To avoid having too generic actions names, you might should prefix the actions names like (and keep the upper case convention) : @trampss/SET_TODOS
The name simpleObject
is misleading. We expect that the value backed by this factory have to be an object. Perhaps we can make it more obvious by naming it simpleValue
which more clearly indicate that this factory is backing any kind of value.
reducer.getBy('a.path', [valeur1, valeur2])
todo : {
visible: false,
title: 'a',
id: 1,
}
reducer.getBy('visible', false)
invariant name
Make the serialized state shrinker
user provide a function to getNextId()
factory(key, generateId, start)(path)(prefix)
factory('id', data => maxBy(data, 'id').id + 1, 1)()('services')
From @EmrysMyrddin (unirakun/k-ramel#60)
It could be useful to allow users to define their own custom actions along with the ones already generated by k-redux-factory.
The actions could be then decorated with dispatch function, allowing the user to easily call it from the store
const store = createStore({
data: simpleObject({
actions: {
load: () => ({ type: 'REQUEST_DATA' }),
loaded: (data) => ({ type: 'DATA_LOADED', payload: { data } }),
},
}),
})
store.data.loaded()
store.data.load({ hello: 'world' })
Since we want to push the use of the redux-saga like API, we want to be able to dispatch very simple action like simple events. For this, our library can also help the user by generating actions for him. You just give a type name for your action and it generate the action creator for you. The action creators can take an optional payload that will be aded to the action.
const store = createStore({
data: simpleObject({
actions: {
load: 'REQUEST_DATA',
loaded: 'REQUEST_DATA',
// Also allows to give a custom action creator implementation
custom: () => ({ type: 'CUSTOM_ACTION' })
},
}),
},{
listeners: [
when(store.data.load.type, (action, store) => store.data.loaded({ hello: 'world' }))
// Dispatch { type: 'DATA_LOADED', payload: { hello: 'world' } }
]
})
I'm not entirely sure of the API. In particular, I'm not convinced by the store.data.load.type
to get the type name of the action. Perhaps by adding a toString
implementation to the function ? Allowing to just do when(store.data.loaded, (...) => ...)
?
replace the selector getById([id]) and getDatas() by uniq selector get()
reducer.get() => return all datas
reducer.get(key) => return the data of key
reducer.get([key]) => return all datas of keys
Only in development builds:
(name, prefix)
[k-redux-factory] You combined two reducers with same name and prefix, we think this is a bug. You should look at 'prefix' option to create your reducer(s)!
@bpetetot are you ok ?
This is related to #73 that is coming back on a regular basis
From @bpetetot
It would be great to have methods to get action names.
It will avoid that reducers will depends on the lib actions names (which can change in the future.
Maybe we can write something like this :
const store = factory('name')
store.add.actionType()
This line is dead to me : dbb7146#diff-91ab3165bff929a787617811e54b40cbR29
and this is uncovered
data
from simpleObject
types
, in this case get
will not be the same for simpleObject
type and keyValue
types/simpleObject/simpleObject.selectors.js
Add .npmignore files
Tests packages with https://docs.npmjs.com/misc/developers#testing-whether-your-npmignore-or-files-config-works
Hey @bpetetot @EmrysMyrddin @frinyvonnick !
I would like to publish the stable release 6.0.0
.
Are you ok with this release ?
The changes ares theses commits: 4224d84...master
There is a rc
published with the next
tag: yarn add k-redux-factory@next
.
If you can test this new version on one of your own project it could be great :)
Thank to all of you.
I put a deadline to the next week so I can move on if I have no response.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.