You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently process() & dispatch() only take argument data. Does that imply the data layer must be referenced in window? e.g. window. dataLayer
My case is I'm using https://github.com/mobxjs/mobx-react where I would like to put the data layer inside props.rootStore. I don't see a way to have it available inside dispatch(), even the react component is a child of the StoreProvider. I tried to hack around with process() but seems the merge will make observers converted to plain object.
Is dispatch(data,props) feasible?
The text was updated successfully, but these errors were encountered:
Hey @vincentlaucy good question. Are you saying you want to be able to push data to rootStore (instead of some global window.dataLayer[])? If so, I think you should be able to push to the rootStore with the current API. Would something like this work?
@inject("rootStore")
@track(ownProps=>({rootStore: ownProps.rootStore// this came from mobx @inject}),{// define `dispatch()` as pushing to rootStore that was made available// from the first argument into @track()dispatch: data=>{const{ rootStore, ...others}=data;// pluck off all data except "rootStore"data.rootStore.push(others);// "push" to the rootStore}})classAppextendsComponent{ ... }
Then, any component that is a descendant of <App /> will utilize this dispatch function.
Let me know if I misunderstood your question, happy to talk through it some more.
Thanks for quick response! I took a quick try but got an error abt max. call stack. Seems some quirks about mobx not playing well with merge() , will investigate a bit more when I have time
Currently
process()
&dispatch()
only take argument data. Does that imply the data layer must be referenced in window? e.g. window. dataLayerMy case is I'm using https://github.com/mobxjs/mobx-react where I would like to put the data layer inside
props.rootStore
. I don't see a way to have it available insidedispatch()
, even the react component is a child of the StoreProvider. I tried to hack around withprocess()
but seems the merge will make observers converted to plain object.Is
dispatch(data,props)
feasible?The text was updated successfully, but these errors were encountered: