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

Replace defaultOptions with addOptions #2088

Merged
merged 9 commits into from Oct 26, 2021

Conversation

philippkuehn
Copy link
Contributor

@philippkuehn philippkuehn commented Oct 26, 2021

This PR changes how default options are defined in extensions.

This has the following advantages:

  • more consistent naming (like addStorage, addInputRules, addProseMirrorPlugins, …)
  • when extending you can use this.parent within addOptions like everywhere else
  • within addOptions() you have access to this.name which is useful in some situations

Since this is a breaking change, a warning is thrown if you keep using defaultOptions.
But it will remain backwards compatible for a while.

Before:

// define extension
const extension = Extension.create({
  defaultOptions: {
    awesomeness: 100,
  },
})

// extend options
const extendedExtension = extension.extend({
  defaultOptions: {
    ...extension.options,
    epicness: 100,
  },
})

After:

// define extension
const extension = Extension.create({
  addOptions() {
    return {
      awesomeness: 100,
    }
  },
})

// extend options
const extendedExtension = extension.extend({
  addOptions() {
    return {
      ...this.parent?.(),
      epicness: 100,
    }
  },
})

@philippkuehn philippkuehn mentioned this pull request Oct 26, 2021
10 tasks
@philippkuehn philippkuehn merged commit 9afadeb into main Oct 26, 2021
@philippkuehn philippkuehn deleted the feature/replace-default-options-with-add-options branch October 26, 2021 16:31
thet added a commit to Patternslib/pat-tiptap that referenced this pull request Jan 17, 2022
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.

None yet

1 participant