Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toReducerFromPath as a helper function #311

Open
acatl opened this issue Dec 13, 2018 · 0 comments
Open

Add toReducerFromPath as a helper function #311

acatl opened this issue Dec 13, 2018 · 0 comments

Comments

@acatl
Copy link
Collaborator

acatl commented Dec 13, 2018

Problem description:

The path reducer allows us to get a specific path from an input object, but at times we want to manipulate the object afterward, because of the nature of reducers being async, adding multiple reducers could not be the most optimal.

['$sone.path.here', syncMethod]

Suggested solution:

Create a higher order function reducer that will output a reducer that executes a given method with its input being the result of a lookup on an Object's path:

// over simplified:
const toReducerFromPath = (method) => (valuePath, defaultValue) => (value) => method(get(valuePath, defaultValue))
// So  instead of this: 
dataPoint.resolve(['$some.path.zipCode',  _.toInteger], input)

// To this: 
const toIntegerFromPath = toReducerFromPath(_.toInteger)

dataPoint.resolve(toIntegerFromPath('$some.path.zipCode'), input)

is toPathReducer the best name?

AC:

  • This method could be exposed under require(data-point/helpers)
  • if no valuePath is received then execute the method against the reducer's value
  • should use same path parser the pathReducer uses
@acatl acatl changed the title Add toPathReducer as a helper function Add toReducerFromPath as a helper function Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant