unirakun / k-ramel

State manager for your components apps, the safe and easy way
MIT License
21 stars 5 forks source link

Avoiding evals ? #132

Closed fabienjuif closed 6 years ago

fabienjuif commented 6 years ago

See : https://github.com/alakarteio/k-ramel/pull/127#discussion_r175028357

fabienjuif commented 6 years ago

lodash:

So I guess this is OK to loop over path as you suggested @bpetetot

Something like you wrote:

const reducerPath = path.split('.')
const reducerName = reducerPath.pop()
const reducerLocation = reducerPath.reduce((acc, next) => acc[next], definitionWithDrivers)
reducerLocation[reducerName] = reducer
EmrysMyrddin commented 6 years ago

You can shorten this with

const [reducerName, reducerPath] = path.split('.')
bpetetot commented 6 years ago

No I dont think you can do that, because reducerName will be the first element and reducerPath the second element of the splitted array.

reducerName must be the last element and reducerPath the rest of the splitted array.

EmrysMyrddin commented 6 years ago

Ha, ok I didn't understand that ^^

fabienjuif commented 6 years ago

Feel free to open a PR if you want to :) Just say it here (or assign issue yourself)

fabienjuif commented 6 years ago

https://github.com/alakarteio/k-redux-factory/pull/116/files#diff-91ab3165bff929a787617811e54b40cbR1