Tremendous, beautiful plugin docs
This commit is contained in:
@@ -192,7 +192,7 @@
|
||||
<a href="custom-layout.html">
|
||||
|
||||
|
||||
Creating a Custom Layout
|
||||
Creating a custom layout
|
||||
|
||||
</a>
|
||||
|
||||
@@ -349,7 +349,7 @@
|
||||
statePlugins: {
|
||||
example: {
|
||||
actions: {
|
||||
updateFavoriteColor: (str) => {
|
||||
updateFavoriteColor: (obj) => {
|
||||
<span class="hljs-keyword">return</span> {
|
||||
type: <span class="hljs-string">"EXAMPLE_SET_FAV_COLOR"</span>,
|
||||
payload: str
|
||||
@@ -361,16 +361,183 @@
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<pre><code class="lang-js"><span class="hljs-comment">// elsewhere</span>
|
||||
exampleActions.updateFavoriteColor({
|
||||
name: <span class="hljs-string">"blue"</span>,
|
||||
hex: <span class="hljs-string">"#0000ff"</span>
|
||||
})
|
||||
</code></pre>
|
||||
<p>The Action interface enables the creation of new Redux action creators within a piece of state in the Swagger-UI system.</p>
|
||||
<p>This action creator function will be bound to the <code>example</code> reducer dispatcher and exposed to container components as <code>exampleActions.updateFavoriteColor</code>.</p>
|
||||
<p>For more information about the concept of actions in Redux, see the <a href="http://redux.js.org/docs/basics/Actions.html" target="_blank">Redux Actions documentation</a>.</p>
|
||||
<h5 id="reducers">Reducers</h5>
|
||||
<p>Reducers take a state (which is an Immutable map) and an action, and return a new state.</p>
|
||||
<p>Reducers must be provided to the system under the name of the action type that they handle, in this case, <code>MYPLUGIN_UPDATE_SOMETHING</code>.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MyReducerPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
example: {
|
||||
reducers: {
|
||||
<span class="hljs-string">"EXAMPLE_SET_FAV_COLOR"</span>: (state, action) => {
|
||||
<span class="hljs-comment">//</span>
|
||||
<span class="hljs-keyword">return</span> state.set(<span class="hljs-string">"favColor"</span>, fromJS(action.payload))
|
||||
<span class="hljs-comment">// we're updating the Immutable state object...</span>
|
||||
<span class="hljs-comment">// we need to convert vanilla objects into an immutable type (fromJS)</span>
|
||||
<span class="hljs-comment">// See immutable docs about how to modify the state</span>
|
||||
<span class="hljs-comment">// PS: you're only working with the state under the namespace, in this case "example".</span>
|
||||
<span class="hljs-comment">// So you can do what you want, without worrying about /other/ namespaces</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h5 id="selectors">Selectors</h5>
|
||||
<p>Selectors take any number of functions as arguments, and passes all results to the last function.</p>
|
||||
<p>They're an easy way to keep logic for getting data out of state in one place, and is preferred over passing state data directly into components.</p>
|
||||
<p>See <a href="https://github.com/reactjs/reselect#createselectorinputselectors--inputselectors-resultfunc" target="_blank">Reselect: <code>createSelector</code></a> for more information.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MySelectorPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
myPlugin: {
|
||||
selectors: {
|
||||
something: createSelector(
|
||||
state => state.get(<span class="hljs-string">"something"</span>) <span class="hljs-comment">// return the whatever "something" points to</span>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h5 id="components">Components</h5>
|
||||
<p>You can provide a map of components to be integrated into the system.</p>
|
||||
<p>Be mindful of the key names for the components you provide, as you'll need to use those names to refer to the components elsewhere.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MyComponentPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
components: {
|
||||
<span class="hljs-comment">// components can just be functions</span>
|
||||
HelloWorld: () => <span class="xml"><span class="hljs-tag"><<span class="hljs-name">h1</span>></span>Hello World!<span class="hljs-tag"></<span class="hljs-name">h1</span>></span></span>
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<pre><code class="lang-js"><span class="hljs-comment">// elsewhere</span>
|
||||
<span class="hljs-keyword">const</span> HelloWorld = getComponent(<span class="hljs-string">"HelloWorld"</span>)
|
||||
</code></pre>
|
||||
<h5 id="wrap-actions">Wrap-Actions</h5>
|
||||
<p>Wrap Actions allow you to override the behavior of an action in the system.</p>
|
||||
<p>This interface is very useful for building custom behavior on top of builtin actions.</p>
|
||||
<p>A Wrap Action's first argument is <code>oriAction</code>, which is the action being wrapped. It is your responsibility to call the <code>oriAction</code> - if you don't, the original action will not fire!</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MySpecPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
actions: {
|
||||
updateSpec: (str) => {
|
||||
<span class="hljs-keyword">return</span> {
|
||||
type: <span class="hljs-string">"SPEC_UPDATE_SPEC"</span>,
|
||||
payload: str
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="hljs-comment">// this plugin allows you to watch changes to the spec that is in memory</span>
|
||||
<span class="hljs-keyword">const</span> MyWrapActionPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
wrapActions: {
|
||||
updateSpec: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">oriAction, str</span>) </span>{
|
||||
doSomethingWithSpecValue(str)
|
||||
<span class="hljs-keyword">return</span> oriAction(str) <span class="hljs-comment">// don't forget!</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h5 id="wrap-selectors">Wrap-Selectors</h5>
|
||||
<p>Wrap Selectors allow you to override the behavior of a selector in the system.</p>
|
||||
<p>They are function factories with the signature <code>(oriSelector, system) => (...args) => result</code>.</p>
|
||||
<p>This interface is useful for controlling what data flows into components. We use this in the core code to disable selectors based on the API definition's version.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { createSelector } <span class="hljs-keyword">from</span> <span class="hljs-string">'reselect'</span>
|
||||
|
||||
<span class="hljs-keyword">const</span> MySpecPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
selectors: {
|
||||
someData: createSelector(
|
||||
state => state.get(<span class="hljs-string">"something"</span>)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">const</span> MyWrapSelectorsPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
statePlugins: {
|
||||
spec: {
|
||||
wrapSelectors: {
|
||||
someData: (oriSelector, system) => (...args) => {
|
||||
<span class="hljs-comment">// you can do other things here...</span>
|
||||
<span class="hljs-comment">// but let's just enable the default behavior</span>
|
||||
<span class="hljs-keyword">return</span> oriSelector(...args)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<h5 id="wrap-components">Wrap-Components</h5>
|
||||
<p>Wrap Components allow you to override a component registered within the system.</p>
|
||||
<p>Wrap Components are function factories with the signature <code>(OriginalComponent, system) => props => ReactElement</code>.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">const</span> MyNumberDisplayPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
components: {
|
||||
NumberDisplay: ({ number }) => <span class="xml"><span class="hljs-tag"><<span class="hljs-name">span</span>></span>{number}<span class="hljs-tag"></<span class="hljs-name">span</span>></span></span>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">const</span> MyWrapComponentPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
wrapComponents: {
|
||||
NumberDisplay: (Original, system) => (props) => {
|
||||
<span class="hljs-keyword">if</span>(props.number > <span class="hljs-number">10</span>) {
|
||||
<span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag"><<span class="hljs-name">div</span>></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">h3</span>></span>Warning! Big number ahead.<span class="hljs-tag"></<span class="hljs-name">h3</span>></span>
|
||||
<span class="hljs-tag"></<span class="hljs-name">div</span>></span></span>
|
||||
} <span class="hljs-keyword">else</span> {
|
||||
<span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag"><<span class="hljs-name">Original</span> {<span class="hljs-attr">...props</span>} /></span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</span></code></pre>
|
||||
<h5 id="fn">fn</h5>
|
||||
<p>The fn interface allows you to add helper functions to the system for use elsewhere.</p>
|
||||
<pre><code class="lang-js"><span class="hljs-keyword">import</span> leftPad <span class="hljs-keyword">from</span> <span class="hljs-string">"left-pad"</span>
|
||||
|
||||
<span class="hljs-keyword">const</span> MyFnPlugin = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">system</span>) </span>{
|
||||
<span class="hljs-keyword">return</span> {
|
||||
fn: {
|
||||
leftPad: leftPad
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
||||
</section>
|
||||
@@ -398,7 +565,7 @@
|
||||
|
||||
|
||||
|
||||
<a href="custom-layout.html" class="navigation navigation-prev " aria-label="Previous page: Creating a Custom Layout">
|
||||
<a href="custom-layout.html" class="navigation navigation-prev " aria-label="Previous page: Creating a custom layout">
|
||||
<i class="fa fa-angle-left"></i>
|
||||
</a>
|
||||
|
||||
@@ -414,7 +581,7 @@
|
||||
<script>
|
||||
var gitbook = gitbook || [];
|
||||
gitbook.push(function() {
|
||||
gitbook.page.hasChanged({"page":{"title":"Plugin API","level":"3.3","depth":1,"next":{"title":"Architecture overview","level":"4.1","depth":1,"path":"development/architecture.md","ref":"development/architecture.md","articles":[]},"previous":{"title":"Creating a Custom Layout","level":"3.2","depth":1,"path":"customization/custom-layout.md","ref":"customization/custom-layout.md","articles":[]},"dir":"ltr"},"config":{"plugins":["livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Swagger-UI","gitbook":"*"},"file":{"path":"customization/plugin-api.md","mtime":"2017-10-06T07:38:26.729Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-06T04:20:18.617Z"},"basePath":"..","book":{"language":""}});
|
||||
gitbook.page.hasChanged({"page":{"title":"Plugin API","level":"3.3","depth":1,"next":{"title":"Architecture overview","level":"4.1","depth":1,"path":"development/architecture.md","ref":"development/architecture.md","articles":[]},"previous":{"title":"Creating a custom layout","level":"3.2","depth":1,"path":"customization/custom-layout.md","ref":"customization/custom-layout.md","articles":[]},"dir":"ltr"},"config":{"plugins":["livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Swagger-UI","gitbook":"*"},"file":{"path":"customization/plugin-api.md","mtime":"2017-10-06T23:51:05.316Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2017-10-06T04:20:18.617Z"},"basePath":"..","book":{"language":""}});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user