-
Notifications
You must be signed in to change notification settings - Fork 0
/
1c0701dd.d57e9352.js
1 lines (1 loc) · 4.68 KB
/
1c0701dd.d57e9352.js
1
(window.webpackJsonp=window.webpackJsonp||[]).push([[8],{104:function(e,t,r){"use strict";r.d(t,"a",(function(){return p})),r.d(t,"b",(function(){return b}));var n=r(0),a=r.n(n);function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function i(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function c(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?i(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function l(e,t){if(null==e)return{};var r,n,a=function(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(a[r]=e[r])}return a}var d=a.a.createContext({}),s=function(e){var t=a.a.useContext(d),r=t;return e&&(r="function"==typeof e?e(t):c(c({},t),e)),r},p=function(e){var t=s(e.components);return a.a.createElement(d.Provider,{value:t},e.children)},u={inlineCode:"code",wrapper:function(e){var t=e.children;return a.a.createElement(a.a.Fragment,{},t)}},m=a.a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,i=e.parentName,d=l(e,["components","mdxType","originalType","parentName"]),p=s(r),m=n,b=p["".concat(i,".").concat(m)]||p[m]||u[m]||o;return r?a.a.createElement(b,c(c({ref:t},d),{},{components:r})):a.a.createElement(b,c({ref:t},d))}));function b(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,i=new Array(o);i[0]=m;var c={};for(var l in t)hasOwnProperty.call(t,l)&&(c[l]=t[l]);c.originalType=e,c.mdxType="string"==typeof e?e:n,i[1]=c;for(var d=2;d<o;d++)i[d]=r[d];return a.a.createElement.apply(null,i)}return a.a.createElement.apply(null,r)}m.displayName="MDXCreateElement"},77:function(e,t,r){"use strict";r.r(t),r.d(t,"frontMatter",(function(){return o})),r.d(t,"metadata",(function(){return i})),r.d(t,"toc",(function(){return c})),r.d(t,"default",(function(){return d}));var n=r(3),a=(r(0),r(104));const o={id:"middleware",title:"Middleware",sidebar_label:"Middleware",slug:"/middleware"},i={unversionedId:"middleware",id:"middleware",isDocsHomePage:!1,title:"Middleware",description:"You can add a middleware to modify the behaviour of the inbuilt actions provided by Formst. For example, you can modify a form value by intercepting the setValue action.",source:"@site/docs/middleware.md",slug:"/middleware",permalink:"/docs/middleware",editUrl:"https://github.com/formstjs/formst-docs/docs/middleware.md",version:"current",sidebar_label:"Middleware",sidebar:"someSidebar",previous:{title:"Nested Forms",permalink:"/docs/nested"},next:{title:"createFormModel",permalink:"/docs/api/create-form-model"}},c=[{value:"Usage",id:"usage",children:[]}],l={toc:c};function d({components:e,...t}){return Object(a.b)("wrapper",Object(n.a)({},l,t,{components:e,mdxType:"MDXLayout"}),Object(a.b)("p",null,"You can add a middleware to modify the behaviour of the inbuilt actions provided by ",Object(a.b)("strong",{parentName:"p"},"Formst"),". For example, you can modify a form value by intercepting the ",Object(a.b)("inlineCode",{parentName:"p"},"setValue")," action."),Object(a.b)("p",null,"Formst exports ",Object(a.b)("a",Object(n.a)({parentName:"p"},{href:"https://mobx-state-tree.js.org/concepts/middleware"}),"addMiddleware")," from MobX state tree. You can refer to ",Object(a.b)("a",Object(n.a)({parentName:"p"},{href:"https://mobx-state-tree.js.org/concepts/middleware"}),"their documentation")," for detailed usage and API details."),Object(a.b)("h3",{id:"usage"},"Usage"),Object(a.b)("pre",null,Object(a.b)("code",Object(n.a)({parentName:"pre"},{className:"language-tsx"}),"const TodoForm = createFormModel(\n 'TodoForm',\n {\n title: types.string,\n description: types.string,\n },\n ...\n);\n\naddMiddleware(TodoForm, (call, next, abort) => {\n if (call.name === 'setValue') {\n const fieldName = call.args[0];\n if (fieldName === 'title') {\n call.args[1] = call.args[1].toUpperCase();\n }\n }\n\n next(call);\n});\n")),Object(a.b)("p",null,"To get all the available actions for a form model, refer to the ",Object(a.b)("a",Object(n.a)({parentName:"p"},{href:"https://github.com/formstjs/formst/blob/master/src/createFormModel.ts"}),"source code"),"."))}d.isMDXComponent=!0}}]);