Skip to content

Migration path : 2.x to 3.x

Jimmy Somsanith edited this page Nov 14, 2019 · 1 revision

Summary

  • UIForm: trigger properties return
  • CMF: remove event from onEvent and cmf.bootstrap has no default settings url anymore

UIForm

In 2.x,

  • it can be an object or a modifier function
  • the object overrides the form properties only in ComponentForm, not UIForm
  • the modifier is applied in UIForm

In 3.x, we manage the trigger properties return only in UIForm.

  • if properties is an object, it overrides the UIForm data
  • if properties is a function, it apply that function on the UIForm data
  • the trigger properties return is no longer managed by ComponentForm

What is the impact on your code ?

It impacts your code only if you use UIForm directly (not ComponentForm), and perform triggers.
Your trigger should returns only what needs to be changed (properties, errors, ...). It was a mistake from the beginning to always return the properties it receives, but they were not handled at the time.
If you don't need to update something in the form, don't return it.

function onTrigger({ properties, errors, schema, trigger }) {
    // code that doesn't alter properties, but alter errors
    // ...

-    return Promise.resolve({ properties, errors });
+    return Promise.resolve({ errors });
}

CMF

Avoid to generate SyntheticEvent automatically by providing an empty object instead of nested object with potential circular dependencies.

If you need data from the event initial, implement your own handler and extract your data to build your own minimum meaningful payload

// before
const submitButtonProps = {
	type: 'submit',
	label: 'Select that',
	onClickDispatch: { type: SUBMIT_ACTION },
};

// after
const submitButtonProps = dispatch => {
	const dispatchSubmit = e =>
		dispatch({ type: SUBMIT_ACTION, payload: { target: e.target } });
	return {
		type: 'submit',
		label: 'Select that',
		onClick: dispatchSubmit,
	};
};

cmf.bootstrap doesn't have a default settingsURL value anymore. Without settingsURL, no settings will be fetched.

To set back the previous behavior, you just need to pass the settingsURL

// before
cmf.bootstrap({
    // attributes without settingsURL
});

// after
cmf.bootstrap({
    settingsURL: '/settings.json'
});