Skip to content

Add docs on repeated use calls targeting the same plugin#80

Merged
wooorm merged 3 commits intounifiedjs:masterfrom
marko-knoebl:readme-repeated-use-same-plugin
Jan 27, 2020
Merged

Add docs on repeated use calls targeting the same plugin#80
wooorm merged 3 commits intounifiedjs:masterfrom
marko-knoebl:readme-repeated-use-same-plugin

Conversation

@marko-knoebl
Copy link
Copy Markdown
Contributor

@marko-knoebl marko-knoebl commented Nov 23, 2019

This adds the description discussed in #79

@wooorm
Copy link
Copy Markdown
Member

wooorm commented Jan 15, 2020

Sorry for letting this sit! (note we have a strict markdown code style so make sure to run npm test locally to make sure your markdown passes).

Your line looks good but I think we should also add an example. What do you think of this, at the end of uses example section?

Note that when the same plugin is given multiple times, it will be attached
once and options are merged:

```js
var unified = require('unified')

unified()
  .use(plugin, {alpha: true, bravo: true})
  .use(plugin, {bravo: false, charlie: true})
  //

function plugin(options) {
  console.log(options) // {alpha: true, bravo: false, charlie: true}
}
```

@wooorm wooorm added 📚 area/docs This affects documentation 🙆 yes/confirmed This is confirmed and ready to be worked on labels Jan 15, 2020
@codecov-io

This comment has been minimized.

@marko-knoebl
Copy link
Copy Markdown
Contributor Author

I'm finally getting back to this again. Just adapted the line length.

I think the example would be a good addition, but I'm not sure where you're suggesting to put it?

@wooorm
Copy link
Copy Markdown
Member

wooorm commented Jan 24, 2020

I was thinking right after the current example in that section?

So right before this heading: https://github.com/unifiedjs/unified#processorparsefile

@marko-knoebl
Copy link
Copy Markdown
Contributor Author

One other suggestion - what would you think of including all examples in one piece of code as below? I think it would not add as much "clutter"

var unified = require('unified')

unified()
  // Plugin with options:
  .use(pluginA, {x: true, y: true})
  // Plugins:
  .use([pluginB, pluginC])
  // Two plugins, the second with options:
  .use([pluginD, [pluginE, {}]])
  // Preset with plugins and settings:
  .use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
  // Settings only:
  .use({settings: {position: false}})
  // Updating options of pluginA (to {x: true, y: false, z: true}):
  .use(pluginA, {y: false, z: true})

@wooorm
Copy link
Copy Markdown
Member

wooorm commented Jan 26, 2020

That’s a great idea!! ✨

I would do it immediately after pluginA tho:

  // Plugin with options:
  .use(pluginA, {x: true, y: true})
  // Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
  .use(pluginA, {y: false, z: true})

Like so maybe?

@marko-knoebl
Copy link
Copy Markdown
Contributor Author

Sounds good, I've incorporated the changes

@wooorm wooorm changed the title readme: documenting behavior of repeated use calls targeting same plugin Add docs on repeated use calls targeting the same plugin Jan 27, 2020
@wooorm wooorm merged commit 952e15d into unifiedjs:master Jan 27, 2020
@wooorm wooorm added ⛵️ status/released and removed 🙆 yes/confirmed This is confirmed and ready to be worked on labels Jan 27, 2020
@wooorm
Copy link
Copy Markdown
Member

wooorm commented Jan 27, 2020

Thank you!

@wooorm wooorm added the 💪 phase/solved Post is done label May 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 area/docs This affects documentation 💪 phase/solved Post is done

Development

Successfully merging this pull request may close these issues.

3 participants