Skip to content
This repository has been archived by the owner on Jan 12, 2020. It is now read-only.

add es build (expose es module in package) + add custom formatter #1

Closed

Conversation

AlexandreBonaventure
Copy link

This PR exposes native module for webpack 2

  • add a feature for formatting copied value (so it provides an easy to insert default to local state or clone, etc..)

example:

mixins: [
      propsToLocal({
        node: {
          required: true,
          formatter: (value) => defaults({ data: { kind: null } }, value),
        },
      }),
    ],

@skyrpex
Copy link
Owner

skyrpex commented Mar 25, 2017

Hi there!

Could you please split this MR into the following?

  • The babel configuration and the package.json change (I'll accept this ASAP, and will build and commit the files myself).
  • The deep option (that's a nice addition; will merge ASAP and build too).
  • The formatter option.

I can do it by myself if you don't mind not appearing in the commits. It's your call.

I want to discuss the formatter option. You can use the default attribute of the prop to fill the local data with default values.

Maybe the problem lies on props that are deeply nested objects (they will be shared, not copied). For that reason, I'd just use _.cloneDeep instead of custom formatters.

@AlexandreBonaventure
Copy link
Author

Not sure how it's possible to update this PR to split it so I created some new PR's
-esbuild: #2

@AlexandreBonaventure
Copy link
Author

AlexandreBonaventure commented Mar 30, 2017

I want to discuss the formatter option. You can use the default attribute of the prop to fill the local data with default values.

Formatter option is more than assigning default.
I use this package to handle forms in which datas are coming from server. This allow me to have consistent data formatting handle directly inside the component no matter what datas are passthrough.

Ex: Let's say I have some data pass to my form :

{
  email: '[email protected]'
  name: 'Alex'
}

I want this data to prefill my form, but I have also a telephone field. Formatter allow me to

propsToLocal({
  form: {
    required: true,
    formatter: (value) => deepDefaults(value, { 
      email: ''
      name: '',
      telephone: ''
     }),
  },
})

without having the boilerplate to do it inside component, plus it handle nicely default field merging on update (with watching handler)

Does that make more sense to you ?

@skyrpex
Copy link
Owner

skyrpex commented Mar 30, 2017

Yes, thanks for the explanation. You can't replicate that behavior without creating watchers again... so yeah! We'll go ahead with this.

If you feel like creating another MR with the changes, that'd be perfect. I have a few small changes in mind (using _.noop and _.omit), but I can do it myself after merging. Then, I'll tag it.

@skyrpex
Copy link
Owner

skyrpex commented Apr 3, 2017

I finally did it in tag v1.2.0.

@skyrpex skyrpex closed this Apr 3, 2017
@AlexandreBonaventure
Copy link
Author

Great ! Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants