Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental plugin accumulator #42

Merged
merged 5 commits into from
Jan 24, 2020
Merged

Add experimental plugin accumulator #42

merged 5 commits into from
Jan 24, 2020

Conversation

benbriggs
Copy link
Contributor

Currently all plugin options are accumulated and passed to the base Editor component by higher-order components returned by createPlugin at render time. While this is often useful for plugin uses cases that require their own custom HOC, the options defined by a plugin built with createPlugin are going to be static in a way that doesn't require their accumulation to be done at render time.

We're experimenting with moving as many operations as possible to build the full configuration of a plugin outside of the render tree. This should provide some significant render performance increases on each input in an editor with a non-trivial number of plugins.

This change adds the ability to immediately accumulate Editor component prop values when passed a configuration object to accumulate onto with an additional __isAccumulator: true property on the object. Adding this flag should allow us to support this behavior without any breaking changes to createPlugin.

The eventually real-world API of this change will handle the __isAccumulator flag for an app. Right now internally it looks something like this, where createPluginStack accumulates a full configuration within its invocation:

const plugins = [
// ...a bunch of draft-extend-compatible plugins, probably built using `createPlugin`
];

const pluginStack = createPluginStack(...plugins);
const EditorWithPlugins = pluginStack(Editor);

The result of this will be a single higher-order component wrapping the base Editor, rather than one per plugin, with no accumulation done on each render besides any additional options received as props from the app by the higher-order component.

This now means plugins are a factory function that takes an object...that returns a higher-order function...that sometimes acts a regular function...that can return an object. My hope is to validate that thinking about plugins more directly as objects in this setup works effectively without making breaking changes. If that's the case, then I'd like to move plugins to be actual objects as much as possible, heavily inspired by slate's plugin organization

@benbriggs benbriggs merged commit b85835d into master Jan 24, 2020
@benbriggs benbriggs deleted the plugin-accumulator branch January 24, 2020 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant