pass args to addNode that are passed to the factory
How do you pass arguments to addNode that are then passed to the factory?
assume you have some code that adds a tab
let args = { type:"tab", component:"MyComponent", name:tabName};
this.state.tabModel.doAction(Actions.addNode(args, "1", DockLocation.CENTER, -1));
and then in your factory
else if (component === "MyComponent"){
let tabName = node.getName();
let foo = node ???
return <MyComponent foo={foo} />
}
I've had a look at the source and extra in TabNode looks promising but it is not passed in from addNode
You can use the config attribute on the node for this, config is saved when the model serialized to json. Alternatively you could create the node with an explicit id, then get it by its id (model.getNodeById()) and use the method getExtraData() to get the extra data object and add attributes to it.
thanks for your reply. how about if i made a pull request whereby you can pass down extra which gets assigned into TabNode - something like this
const newNode = new TabNode(this, action.data.json, action.data.extra);
the ctor on TabNode could be easily modified to take extra as an optional param
Why does using the config attribute not fit your use case? ie let args = { type:"tab", component:"MyComponent", name:tabName, config:{your arguments object goes here}};
because it is serialized on save?
So if you saved your layout to localstorage/server and then reloaded it later into your gui, where would the arguments for the MyComponent come from?
I'm just trying to understand why you prefer 'extra' over 'config' here.
The config attribute is for passing initial arguments to the component (via the factory), the extra property is for other values that you wish to store on the node, but are not saved/restored when you serialize the model.
the component is showing data that has been loaded from an api call - in this case the data is already loaded however if the component had to fetch it itself (or get it from redux) the same issue would apply as it needs to know the subset of data it is displaying - e.g. the component might be showing a list of items filtered according to a certain criteria.
OK, I see. Please go ahead and add your pull request for optionally setting the extra property