mobx-web-cell
Version:
MobX adaptor for WebCell v2
1 lines • 1.39 kB
Source Map (JSON)
{"mappings":";AASA,8BAA8B,CAAC,SAAS,YAAY,GAAG,YAAY,IAAI,CACnE,KAAK,CAAC,EAAE,CAAC,KACR,KAAK,CAAC;AAqBX,yBAAyB,CAAC,EAAE,CAAC,EACzB,KAAK,EAAE,kBAAkB,CAAC,CAAC,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC,GACjD,GAAG,CAKL","sources":["source/source/index.ts","source/index.ts"],"sourcesContent":[null,"import {\n WebCellProps,\n WebCellClass,\n WebCellComponent,\n VNode,\n patch\n} from 'web-cell';\nimport { autorun } from 'mobx';\n\nexport type FunctionComponent<P extends WebCellProps = WebCellProps> = (\n props?: P\n) => VNode;\n\nfunction wrapFunction<P>(func: FunctionComponent<P>) {\n return function (props?: P) {\n var vTree: VNode;\n\n autorun(\n () => (vTree = vTree ? patch(vTree, func(props)) : func(props))\n );\n return vTree;\n };\n}\n\nfunction wrapClass<P, S>(Class: WebCellClass<P, S>) {\n const { update } = Class.prototype as WebCellComponent<P, S>;\n\n Class.prototype.update = function (this: WebCellComponent<P, S>) {\n autorun(() => this.isConnected && update.call(this));\n };\n}\n\nexport function observer<P, S>(\n Class: FunctionComponent<P> | WebCellClass<P, S>\n): any {\n if (Object.getPrototypeOf(Class) === Function.prototype)\n return wrapFunction(Class as FunctionComponent<P>);\n\n wrapClass(Class as WebCellClass<P, S>);\n}\n"],"names":[],"version":3,"file":"index.d.ts.map"}