modelizr icon indicating copy to clipboard operation
modelizr copied to clipboard

Unable to use the normalize function independently

Open swinyx opened this issue 7 years ago • 2 comments

Is the normalize function available globally? What if I need to normalize something that is not being fetched via an API ?

It does not work when I import the normalizr package to my project and use that function with the modelizr schema

swinyx avatar Oct 03 '17 15:10 swinyx

Modelizr schema's aren't compatible with Normalizr. Unfortunately Modelizr doesn't currently expose a way to normalize data outside of api calls.

It would be a good addition though and I'd be happy to add. A quick hack for the interim would be to do something like:

import normalize from "modelizr/lib/data/normalization"

normalize({
 data: <Object>, 
 modelFunctions: <ModelizrSchema>, 
 clientState: <ClientState>
})

Where data is the data you want to normalize, modelFunctions is your modelizr schema and clientState is a property from a Modelizr instance - i.e new Modelizr().clientState.

Let me know if that works for you

julienvincent avatar Oct 03 '17 16:10 julienvincent

Thank you.

swinyx avatar Oct 03 '17 20:10 swinyx