From a0b430c78c26a9ae73a9883b2d54fbef6da135b7 Mon Sep 17 00:00:00 2001 From: y1j2x34 Date: Mon, 11 Dec 2023 17:03:33 +0800 Subject: [PATCH] feat: release 1.0.6 --- dist/index.cjs.js | 2 +- dist/index.cjs.js.map | 2 +- dist/index.d.ts | 2 ++ dist/index.esm.js | 2 +- dist/index.esm.js.map | 2 +- dist/index.umd.js | 2 +- dist/index.umd.js.map | 2 +- package.json | 5 +++-- 8 files changed, 11 insertions(+), 8 deletions(-) diff --git a/dist/index.cjs.js b/dist/index.cjs.js index 22fe9ce..3195b06 100644 --- a/dist/index.cjs.js +++ b/dist/index.cjs.js @@ -1,2 +1,2 @@ -"use strict";var e=require("@vgerbot/ioc"),r=require("react"),t=require("mobx"),n=r.createContext(void 0);exports.IoC=function(o){var a=r.useRef();if(!a.current){var c=new e.ApplicationContext;"function"==typeof o.callback&&o.callback(c),c.registerInstAwareProcessor(function(){function e(){}return e.prototype.afterInstantiation=function(e){return c.getClassMetadata(e.constructor).getCtorMarkInfo()["mark-as-mobx-observable"]&&t.makeObservable(e),e},e}()),a.current=c}return r.createElement(n.Provider,{value:a.current},o.children)},exports.Observable=function(){return e.Mark("mark-as-mobx-observable",!0)},exports.useService=function(e){var t=r.useContext(n);if(!t)throw new Error(" has not been applied to the component.");return t.getInstance(e)},Object.keys(e).forEach((function(r){"default"===r||exports.hasOwnProperty(r)||Object.defineProperty(exports,r,{enumerable:!0,get:function(){return e[r]}})})); +"use strict";var e=require("@vgerbot/ioc"),r=require("react"),t=require("mobx"),o=require("mobx-react-lite"),n=r.createContext(void 0);exports.AutoObservable=function(){return e.Mark("mark-as-mobx-auto-observerable",!0)},exports.IoC=function(o){var a=r.useRef();if(!a.current){var s=new e.ApplicationContext;"function"==typeof o.callback&&o.callback(s),s.registerInstAwareProcessor(function(){function e(){}return e.prototype.afterInstantiation=function(e){var r=s.getClassMetadata(e.constructor).getCtorMarkInfo();return r["mark-as-mobx-observable"]&&t.makeObservable(e),r["mark-as-mobx-auto-observerable"]&&t.makeAutoObservable(e),e},e}()),a.current=s}return r.createElement(n.Provider,{value:a.current},o.children)},exports.Observable=function(){return e.Mark("mark-as-mobx-observable",!0)},exports.renderObserver=function(e){return r.createElement(o.Observer,{render:e},[])},exports.useService=function(e){var t=r.useContext(n);if(!t)throw new Error(" has not been applied to the component.");return t.getInstance(e)},Object.keys(e).forEach((function(r){"default"===r||exports.hasOwnProperty(r)||Object.defineProperty(exports,r,{enumerable:!0,get:function(){return e[r]}})})); //# sourceMappingURL=index.cjs.js.map diff --git a/dist/index.cjs.js.map b/dist/index.cjs.js.map index b1eabca..a545693 100644 --- a/dist/index.cjs.js.map +++ b/dist/index.cjs.js.map @@ -1 +1 @@ -{"version":3,"file":"index.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import { ApplicationContext, Mark } from '@vgerbot/ioc';\nimport React, { useContext, useRef } from 'react';\nimport { Newable } from '@vgerbot/ioc/dist/types/Newable';\nimport { PartialInstAwareProcessor } from '@vgerbot/ioc/dist/types/InstantiationAwareProcessor';\nimport { makeObservable } from 'mobx';\n\nconst IoCContext = React.createContext(undefined);\n\nconst MARK_AS_MOBX_OBSERVABLE = 'mark-as-mobx-observable';\n\nexport function Observable() {\n return Mark(MARK_AS_MOBX_OBSERVABLE, true);\n}\n\nexport type IoCProps = React.PropsWithChildren<{\n callback?: (appctx: ApplicationContext) => void;\n}>;\n\nexport function IoC(props: IoCProps) {\n const ref = useRef();\n if (!ref.current) {\n const appctx = new ApplicationContext();\n if (typeof props.callback === 'function') {\n props.callback(appctx);\n }\n appctx.registerInstAwareProcessor(\n class implements PartialInstAwareProcessor {\n afterInstantiation(instance: T): T {\n const markInfo = appctx.getClassMetadata(instance.constructor as Newable).getCtorMarkInfo();\n if (markInfo[MARK_AS_MOBX_OBSERVABLE]) {\n makeObservable(instance);\n }\n return instance;\n }\n }\n );\n ref.current = appctx;\n }\n return React.createElement(\n IoCContext.Provider,\n {\n value: ref.current\n },\n props.children\n );\n}\n\nexport function useService(ctor: Newable): T {\n const ctx = useContext(IoCContext);\n if (!ctx) {\n throw new Error(' has not been applied to the component.');\n }\n return ctx.getInstance(ctor);\n}\n\nexport * from '@vgerbot/ioc';\n"],"names":["IoCContext","React","createContext","undefined","props","ref","useRef","current","appctx_1","ApplicationContext","callback","registerInstAwareProcessor","class_1","prototype","afterInstantiation","instance","getClassMetadata","constructor","getCtorMarkInfo","makeObservable","createElement","Provider","value","children","Mark","ctor","ctx","useContext","Error","getInstance"],"mappings":"gFAMMA,EAAaC,EAAMC,mBAA8CC,eAYjE,SAAcC,GAChB,IAAMC,EAAMC,EAAAA,SACZ,IAAKD,EAAIE,QAAS,CACd,IAAMC,EAAS,IAAIC,EAAAA,mBACW,mBAAnBL,EAAMM,UACbN,EAAMM,SAASF,GAEnBA,EAAOG,2BAA0B,WAC7B,SAAAC,KAQA,OAPIA,EAAkBC,UAAAC,mBAAlB,SAAqCC,GAKjC,OAJiBP,EAAOQ,iBAAiBD,EAASE,aAA2BC,kBApBjE,4BAsBRC,EAAcA,eAACJ,GAEZA,GAEdH,EAT4B,IAWjCP,EAAIE,QAAUC,EAElB,OAAOP,EAAMmB,cACTpB,EAAWqB,SACX,CACIC,MAAOjB,EAAIE,SAEfH,EAAMmB,yCAhCV,OAAOC,EAAIA,KAHiB,2BAGS,uBAoCnC,SAAwBC,GAC1B,IAAMC,EAAMC,aAAW3B,GACvB,IAAK0B,EACD,MAAM,IAAIE,MAAM,sDAEpB,OAAOF,EAAIG,YAAYJ"} \ No newline at end of file +{"version":3,"file":"index.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import { ApplicationContext, Mark } from '@vgerbot/ioc';\nimport React, { useContext, useRef } from 'react';\nimport { Newable } from '@vgerbot/ioc/dist/types/Newable';\nimport { PartialInstAwareProcessor } from '@vgerbot/ioc/dist/types/InstantiationAwareProcessor';\nimport { makeAutoObservable, makeObservable } from 'mobx';\nimport { Observer } from 'mobx-react-lite';\n\nconst IoCContext = React.createContext(undefined);\n\nconst MARK_AS_MOBX_OBSERVABLE = 'mark-as-mobx-observable';\n\nconst MARK_AS_MOBX_AUTO_OBSERVABLE = 'mark-as-mobx-auto-observerable';\n\nexport function Observable() {\n return Mark(MARK_AS_MOBX_OBSERVABLE, true);\n}\n\nexport function AutoObservable() {\n return Mark(MARK_AS_MOBX_AUTO_OBSERVABLE, true);\n}\n\nexport type IoCProps = React.PropsWithChildren<{\n callback?: (appctx: ApplicationContext) => void;\n}>;\n\nexport function IoC(props: IoCProps) {\n const ref = useRef();\n if (!ref.current) {\n const appctx = new ApplicationContext();\n if (typeof props.callback === 'function') {\n props.callback(appctx);\n }\n appctx.registerInstAwareProcessor(\n class implements PartialInstAwareProcessor {\n afterInstantiation(instance: T): T {\n const markInfo = appctx.getClassMetadata(instance.constructor as Newable).getCtorMarkInfo();\n if (markInfo[MARK_AS_MOBX_OBSERVABLE]) {\n makeObservable(instance);\n }\n if(markInfo[MARK_AS_MOBX_AUTO_OBSERVABLE]) {\n makeAutoObservable(instance);\n }\n return instance;\n }\n }\n );\n ref.current = appctx;\n }\n return React.createElement(\n IoCContext.Provider,\n {\n value: ref.current\n },\n props.children\n );\n}\n\nexport function useService(ctor: Newable): T {\n const ctx = useContext(IoCContext);\n if (!ctx) {\n throw new Error(' has not been applied to the component.');\n }\n return ctx.getInstance(ctor);\n}\n\nexport function renderObserver(render: () => React.ReactElement) {\n return React.createElement(\n Observer,\n {\n render: render\n },\n []\n ) as React.ReactElement\n}\n\nexport * from '@vgerbot/ioc';\n"],"names":["IoCContext","React","createContext","undefined","Mark","props","ref","useRef","current","appctx_1","ApplicationContext","callback","registerInstAwareProcessor","class_1","prototype","afterInstantiation","instance","markInfo","getClassMetadata","constructor","getCtorMarkInfo","makeObservable","makeAutoObservable","createElement","Provider","value","children","render","Observer","ctor","ctx","useContext","Error","getInstance"],"mappings":"6GAOMA,EAAaC,EAAMC,mBAA8CC,qCAWnE,OAAOC,EAAIA,KAPsB,kCAOS,gBAOxC,SAAcC,GAChB,IAAMC,EAAMC,EAAAA,SACZ,IAAKD,EAAIE,QAAS,CACd,IAAMC,EAAS,IAAIC,EAAAA,mBACW,mBAAnBL,EAAMM,UACbN,EAAMM,SAASF,GAEnBA,EAAOG,2BAA0B,WAC7B,SAAAC,KAWA,OAVIA,EAAkBC,UAAAC,mBAAlB,SAAqCC,GACjC,IAAMC,EAAWR,EAAOS,iBAAiBF,EAASG,aAA2BC,kBAO7E,OANIH,EA3BQ,4BA4BRI,EAAcA,eAACL,GAEhBC,EA5Bc,mCA6BbK,EAAkBA,mBAACN,GAEhBA,GAEdH,EAZ4B,IAcjCP,EAAIE,QAAUC,EAElB,OAAOR,EAAMsB,cACTvB,EAAWwB,SACX,CACIC,MAAOnB,EAAIE,SAEfH,EAAMqB,yCAvCV,OAAOtB,EAAIA,KALiB,2BAKS,2BAmDnC,SAAyBuB,GAC3B,OAAO1B,EAAMsB,cACTK,WACA,CACID,OAAQA,GAEZ,wBAdF,SAAwBE,GAC1B,IAAMC,EAAMC,aAAW/B,GACvB,IAAK8B,EACD,MAAM,IAAIE,MAAM,sDAEpB,OAAOF,EAAIG,YAAYJ"} \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts index 0889b21..718ebdf 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -2,9 +2,11 @@ import { ApplicationContext } from '@vgerbot/ioc'; import React from 'react'; import { Newable } from '@vgerbot/ioc/dist/types/Newable'; export declare function Observable(): Function; +export declare function AutoObservable(): Function; export type IoCProps = React.PropsWithChildren<{ callback?: (appctx: ApplicationContext) => void; }>; export declare function IoC(props: IoCProps): React.FunctionComponentElement>; export declare function useService(ctor: Newable): T; +export declare function renderObserver(render: () => React.ReactElement): React.ReactElement>; export * from '@vgerbot/ioc'; diff --git a/dist/index.esm.js b/dist/index.esm.js index dc830d2..8ae499c 100644 --- a/dist/index.esm.js +++ b/dist/index.esm.js @@ -1,2 +1,2 @@ -import{Mark as r,ApplicationContext as t}from"@vgerbot/ioc";export*from"@vgerbot/ioc";import e,{useRef as o,useContext as n}from"react";import{makeObservable as a}from"mobx";var c=e.createContext(void 0);function i(){return r("mark-as-mobx-observable",!0)}function u(r){var n=o();if(!n.current){var i=new t;"function"==typeof r.callback&&r.callback(i),i.registerInstAwareProcessor(function(){function r(){}return r.prototype.afterInstantiation=function(r){return i.getClassMetadata(r.constructor).getCtorMarkInfo()["mark-as-mobx-observable"]&&a(r),r},r}()),n.current=i}return e.createElement(c.Provider,{value:n.current},r.children)}function f(r){var t=n(c);if(!t)throw new Error(" has not been applied to the component.");return t.getInstance(r)}export{u as IoC,i as Observable,f as useService}; +import{Mark as r,ApplicationContext as e}from"@vgerbot/ioc";export*from"@vgerbot/ioc";import t,{useRef as o,useContext as n}from"react";import{makeObservable as a,makeAutoObservable as c}from"mobx";import{Observer as i}from"mobx-react-lite";var u=t.createContext(void 0);function m(){return r("mark-as-mobx-observable",!0)}function b(){return r("mark-as-mobx-auto-observerable",!0)}function f(r){var n=o();if(!n.current){var i=new e;"function"==typeof r.callback&&r.callback(i),i.registerInstAwareProcessor(function(){function r(){}return r.prototype.afterInstantiation=function(r){var e=i.getClassMetadata(r.constructor).getCtorMarkInfo();return e["mark-as-mobx-observable"]&&a(r),e["mark-as-mobx-auto-observerable"]&&c(r),r},r}()),n.current=i}return t.createElement(u.Provider,{value:n.current},r.children)}function s(r){var e=n(u);if(!e)throw new Error(" has not been applied to the component.");return e.getInstance(r)}function l(r){return t.createElement(i,{render:r},[])}export{b as AutoObservable,f as IoC,m as Observable,l as renderObserver,s as useService}; //# sourceMappingURL=index.esm.js.map diff --git a/dist/index.esm.js.map b/dist/index.esm.js.map index 46657aa..58d0981 100644 --- a/dist/index.esm.js.map +++ b/dist/index.esm.js.map @@ -1 +1 @@ -{"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["import { ApplicationContext, Mark } from '@vgerbot/ioc';\nimport React, { useContext, useRef } from 'react';\nimport { Newable } from '@vgerbot/ioc/dist/types/Newable';\nimport { PartialInstAwareProcessor } from '@vgerbot/ioc/dist/types/InstantiationAwareProcessor';\nimport { makeObservable } from 'mobx';\n\nconst IoCContext = React.createContext(undefined);\n\nconst MARK_AS_MOBX_OBSERVABLE = 'mark-as-mobx-observable';\n\nexport function Observable() {\n return Mark(MARK_AS_MOBX_OBSERVABLE, true);\n}\n\nexport type IoCProps = React.PropsWithChildren<{\n callback?: (appctx: ApplicationContext) => void;\n}>;\n\nexport function IoC(props: IoCProps) {\n const ref = useRef();\n if (!ref.current) {\n const appctx = new ApplicationContext();\n if (typeof props.callback === 'function') {\n props.callback(appctx);\n }\n appctx.registerInstAwareProcessor(\n class implements PartialInstAwareProcessor {\n afterInstantiation(instance: T): T {\n const markInfo = appctx.getClassMetadata(instance.constructor as Newable).getCtorMarkInfo();\n if (markInfo[MARK_AS_MOBX_OBSERVABLE]) {\n makeObservable(instance);\n }\n return instance;\n }\n }\n );\n ref.current = appctx;\n }\n return React.createElement(\n IoCContext.Provider,\n {\n value: ref.current\n },\n props.children\n );\n}\n\nexport function useService(ctor: Newable): T {\n const ctx = useContext(IoCContext);\n if (!ctx) {\n throw new Error(' has not been applied to the component.');\n }\n return ctx.getInstance(ctor);\n}\n\nexport * from '@vgerbot/ioc';\n"],"names":["IoCContext","React","createContext","undefined","Observable","Mark","IoC","props","ref","useRef","current","appctx_1","ApplicationContext","callback","registerInstAwareProcessor","class_1","prototype","afterInstantiation","instance","getClassMetadata","constructor","getCtorMarkInfo","makeObservable","createElement","Provider","value","children","useService","ctor","ctx","useContext","Error","getInstance"],"mappings":"8KAMA,IAAMA,EAAaC,EAAMC,mBAA8CC,YAIvDC,IACZ,OAAOC,EAHqB,2BAGS,GAOnC,SAAUC,EAAIC,GAChB,IAAMC,EAAMC,IACZ,IAAKD,EAAIE,QAAS,CACd,IAAMC,EAAS,IAAIC,EACW,mBAAnBL,EAAMM,UACbN,EAAMM,SAASF,GAEnBA,EAAOG,2BAA0B,WAC7B,SAAAC,KAQA,OAPIA,EAAkBC,UAAAC,mBAAlB,SAAqCC,GAKjC,OAJiBP,EAAOQ,iBAAiBD,EAASE,aAA2BC,kBApBjE,4BAsBRC,EAAeJ,GAEZA,GAEdH,EAT4B,IAWjCP,EAAIE,QAAUC,EAElB,OAAOV,EAAMsB,cACTvB,EAAWwB,SACX,CACIC,MAAOjB,EAAIE,SAEfH,EAAMmB,UAIR,SAAUC,EAAcC,GAC1B,IAAMC,EAAMC,EAAW9B,GACvB,IAAK6B,EACD,MAAM,IAAIE,MAAM,sDAEpB,OAAOF,EAAIG,YAAYJ"} \ No newline at end of file +{"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["import { ApplicationContext, Mark } from '@vgerbot/ioc';\nimport React, { useContext, useRef } from 'react';\nimport { Newable } from '@vgerbot/ioc/dist/types/Newable';\nimport { PartialInstAwareProcessor } from '@vgerbot/ioc/dist/types/InstantiationAwareProcessor';\nimport { makeAutoObservable, makeObservable } from 'mobx';\nimport { Observer } from 'mobx-react-lite';\n\nconst IoCContext = React.createContext(undefined);\n\nconst MARK_AS_MOBX_OBSERVABLE = 'mark-as-mobx-observable';\n\nconst MARK_AS_MOBX_AUTO_OBSERVABLE = 'mark-as-mobx-auto-observerable';\n\nexport function Observable() {\n return Mark(MARK_AS_MOBX_OBSERVABLE, true);\n}\n\nexport function AutoObservable() {\n return Mark(MARK_AS_MOBX_AUTO_OBSERVABLE, true);\n}\n\nexport type IoCProps = React.PropsWithChildren<{\n callback?: (appctx: ApplicationContext) => void;\n}>;\n\nexport function IoC(props: IoCProps) {\n const ref = useRef();\n if (!ref.current) {\n const appctx = new ApplicationContext();\n if (typeof props.callback === 'function') {\n props.callback(appctx);\n }\n appctx.registerInstAwareProcessor(\n class implements PartialInstAwareProcessor {\n afterInstantiation(instance: T): T {\n const markInfo = appctx.getClassMetadata(instance.constructor as Newable).getCtorMarkInfo();\n if (markInfo[MARK_AS_MOBX_OBSERVABLE]) {\n makeObservable(instance);\n }\n if(markInfo[MARK_AS_MOBX_AUTO_OBSERVABLE]) {\n makeAutoObservable(instance);\n }\n return instance;\n }\n }\n );\n ref.current = appctx;\n }\n return React.createElement(\n IoCContext.Provider,\n {\n value: ref.current\n },\n props.children\n );\n}\n\nexport function useService(ctor: Newable): T {\n const ctx = useContext(IoCContext);\n if (!ctx) {\n throw new Error(' has not been applied to the component.');\n }\n return ctx.getInstance(ctor);\n}\n\nexport function renderObserver(render: () => React.ReactElement) {\n return React.createElement(\n Observer,\n {\n render: render\n },\n []\n ) as React.ReactElement\n}\n\nexport * from '@vgerbot/ioc';\n"],"names":["IoCContext","React","createContext","undefined","Observable","Mark","AutoObservable","IoC","props","ref","useRef","current","appctx_1","ApplicationContext","callback","registerInstAwareProcessor","class_1","prototype","afterInstantiation","instance","markInfo","getClassMetadata","constructor","getCtorMarkInfo","makeObservable","makeAutoObservable","createElement","Provider","value","children","useService","ctor","ctx","useContext","Error","getInstance","renderObserver","render","Observer"],"mappings":"iPAOA,IAAMA,EAAaC,EAAMC,mBAA8CC,YAMvDC,IACZ,OAAOC,EALqB,2BAKS,YAGzBC,IACZ,OAAOD,EAP0B,kCAOS,GAOxC,SAAUE,EAAIC,GAChB,IAAMC,EAAMC,IACZ,IAAKD,EAAIE,QAAS,CACd,IAAMC,EAAS,IAAIC,EACW,mBAAnBL,EAAMM,UACbN,EAAMM,SAASF,GAEnBA,EAAOG,2BAA0B,WAC7B,SAAAC,KAWA,OAVIA,EAAkBC,UAAAC,mBAAlB,SAAqCC,GACjC,IAAMC,EAAWR,EAAOS,iBAAiBF,EAASG,aAA2BC,kBAO7E,OANIH,EA3BQ,4BA4BRI,EAAeL,GAEhBC,EA5Bc,mCA6BbK,EAAmBN,GAEhBA,GAEdH,EAZ4B,IAcjCP,EAAIE,QAAUC,EAElB,OAAOX,EAAMyB,cACT1B,EAAW2B,SACX,CACIC,MAAOnB,EAAIE,SAEfH,EAAMqB,UAIR,SAAUC,EAAcC,GAC1B,IAAMC,EAAMC,EAAWjC,GACvB,IAAKgC,EACD,MAAM,IAAIE,MAAM,sDAEpB,OAAOF,EAAIG,YAAYJ,GAGrB,SAAUK,EAAeC,GAC3B,OAAOpC,EAAMyB,cACTY,EACA,CACID,OAAQA,GAEZ"} \ No newline at end of file diff --git a/dist/index.umd.js b/dist/index.umd.js index f8ea302..6a8b2fb 100644 --- a/dist/index.umd.js +++ b/dist/index.umd.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@vgerbot/ioc"),require("react"),require("mobx")):"function"==typeof define&&define.amd?define(["exports","@vgerbot/ioc","react","mobx"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).useService={},e.ioc,e.React,e.mobx)}(this,(function(e,t,r,n){"use strict";var o=r.createContext(void 0),a="mark-as-mobx-observable";e.IoC=function(e){var c=r.useRef();if(!c.current){var i=new t.ApplicationContext;"function"==typeof e.callback&&e.callback(i),i.registerInstAwareProcessor(function(){function e(){}return e.prototype.afterInstantiation=function(e){return i.getClassMetadata(e.constructor).getCtorMarkInfo()[a]&&n.makeObservable(e),e},e}()),c.current=i}return r.createElement(o.Provider,{value:c.current},e.children)},e.Observable=function(){return t.Mark(a,!0)},e.useService=function(e){var t=r.useContext(o);if(!t)throw new Error(" has not been applied to the component.");return t.getInstance(e)},Object.keys(t).forEach((function(r){"default"===r||e.hasOwnProperty(r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})}))})); +!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("@vgerbot/ioc"),require("react"),require("mobx"),require("mobx-react-lite")):"function"==typeof define&&define.amd?define(["exports","@vgerbot/ioc","react","mobx","mobx-react-lite"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).useService={},e.ioc,e.React,e.mobx,e.mobxReactLite)}(this,(function(e,r,t,n,o){"use strict";var a=t.createContext(void 0),c="mark-as-mobx-observable",i="mark-as-mobx-auto-observerable";e.AutoObservable=function(){return r.Mark(i,!0)},e.IoC=function(e){var o=t.useRef();if(!o.current){var u=new r.ApplicationContext;"function"==typeof e.callback&&e.callback(u),u.registerInstAwareProcessor(function(){function e(){}return e.prototype.afterInstantiation=function(e){var r=u.getClassMetadata(e.constructor).getCtorMarkInfo();return r[c]&&n.makeObservable(e),r[i]&&n.makeAutoObservable(e),e},e}()),o.current=u}return t.createElement(a.Provider,{value:o.current},e.children)},e.Observable=function(){return r.Mark(c,!0)},e.renderObserver=function(e){return t.createElement(o.Observer,{render:e},[])},e.useService=function(e){var r=t.useContext(a);if(!r)throw new Error(" has not been applied to the component.");return r.getInstance(e)},Object.keys(r).forEach((function(t){"default"===t||e.hasOwnProperty(t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})}))})); //# sourceMappingURL=index.umd.js.map diff --git a/dist/index.umd.js.map b/dist/index.umd.js.map index 787f2db..3f7882b 100644 --- a/dist/index.umd.js.map +++ b/dist/index.umd.js.map @@ -1 +1 @@ -{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { ApplicationContext, Mark } from '@vgerbot/ioc';\nimport React, { useContext, useRef } from 'react';\nimport { Newable } from '@vgerbot/ioc/dist/types/Newable';\nimport { PartialInstAwareProcessor } from '@vgerbot/ioc/dist/types/InstantiationAwareProcessor';\nimport { makeObservable } from 'mobx';\n\nconst IoCContext = React.createContext(undefined);\n\nconst MARK_AS_MOBX_OBSERVABLE = 'mark-as-mobx-observable';\n\nexport function Observable() {\n return Mark(MARK_AS_MOBX_OBSERVABLE, true);\n}\n\nexport type IoCProps = React.PropsWithChildren<{\n callback?: (appctx: ApplicationContext) => void;\n}>;\n\nexport function IoC(props: IoCProps) {\n const ref = useRef();\n if (!ref.current) {\n const appctx = new ApplicationContext();\n if (typeof props.callback === 'function') {\n props.callback(appctx);\n }\n appctx.registerInstAwareProcessor(\n class implements PartialInstAwareProcessor {\n afterInstantiation(instance: T): T {\n const markInfo = appctx.getClassMetadata(instance.constructor as Newable).getCtorMarkInfo();\n if (markInfo[MARK_AS_MOBX_OBSERVABLE]) {\n makeObservable(instance);\n }\n return instance;\n }\n }\n );\n ref.current = appctx;\n }\n return React.createElement(\n IoCContext.Provider,\n {\n value: ref.current\n },\n props.children\n );\n}\n\nexport function useService(ctor: Newable): T {\n const ctx = useContext(IoCContext);\n if (!ctx) {\n throw new Error(' has not been applied to the component.');\n }\n return ctx.getInstance(ctor);\n}\n\nexport * from '@vgerbot/ioc';\n"],"names":["IoCContext","React","createContext","undefined","MARK_AS_MOBX_OBSERVABLE","props","ref","useRef","current","appctx_1","ApplicationContext","callback","registerInstAwareProcessor","class_1","prototype","afterInstantiation","instance","getClassMetadata","constructor","getCtorMarkInfo","makeObservable","createElement","Provider","value","children","Mark","ctor","ctx","useContext","Error","getInstance"],"mappings":"oWAMA,IAAMA,EAAaC,EAAMC,mBAA8CC,GAEjEC,EAA0B,gCAU1B,SAAcC,GAChB,IAAMC,EAAMC,EAAAA,SACZ,IAAKD,EAAIE,QAAS,CACd,IAAMC,EAAS,IAAIC,EAAAA,mBACW,mBAAnBL,EAAMM,UACbN,EAAMM,SAASF,GAEnBA,EAAOG,2BAA0B,WAC7B,SAAAC,KAQA,OAPIA,EAAkBC,UAAAC,mBAAlB,SAAqCC,GAKjC,OAJiBP,EAAOQ,iBAAiBD,EAASE,aAA2BC,kBAChEf,IACTgB,EAAcA,eAACJ,GAEZA,GAEdH,EAT4B,IAWjCP,EAAIE,QAAUC,EAElB,OAAOR,EAAMoB,cACTrB,EAAWsB,SACX,CACIC,MAAOjB,EAAIE,SAEfH,EAAMmB,mCAhCV,OAAOC,EAAIA,KAACrB,GAAyB,iBAoCnC,SAAwBsB,GAC1B,IAAMC,EAAMC,aAAW5B,GACvB,IAAK2B,EACD,MAAM,IAAIE,MAAM,sDAEpB,OAAOF,EAAIG,YAAYJ"} \ No newline at end of file +{"version":3,"file":"index.umd.js","sources":["../src/index.ts"],"sourcesContent":["import { ApplicationContext, Mark } from '@vgerbot/ioc';\nimport React, { useContext, useRef } from 'react';\nimport { Newable } from '@vgerbot/ioc/dist/types/Newable';\nimport { PartialInstAwareProcessor } from '@vgerbot/ioc/dist/types/InstantiationAwareProcessor';\nimport { makeAutoObservable, makeObservable } from 'mobx';\nimport { Observer } from 'mobx-react-lite';\n\nconst IoCContext = React.createContext(undefined);\n\nconst MARK_AS_MOBX_OBSERVABLE = 'mark-as-mobx-observable';\n\nconst MARK_AS_MOBX_AUTO_OBSERVABLE = 'mark-as-mobx-auto-observerable';\n\nexport function Observable() {\n return Mark(MARK_AS_MOBX_OBSERVABLE, true);\n}\n\nexport function AutoObservable() {\n return Mark(MARK_AS_MOBX_AUTO_OBSERVABLE, true);\n}\n\nexport type IoCProps = React.PropsWithChildren<{\n callback?: (appctx: ApplicationContext) => void;\n}>;\n\nexport function IoC(props: IoCProps) {\n const ref = useRef();\n if (!ref.current) {\n const appctx = new ApplicationContext();\n if (typeof props.callback === 'function') {\n props.callback(appctx);\n }\n appctx.registerInstAwareProcessor(\n class implements PartialInstAwareProcessor {\n afterInstantiation(instance: T): T {\n const markInfo = appctx.getClassMetadata(instance.constructor as Newable).getCtorMarkInfo();\n if (markInfo[MARK_AS_MOBX_OBSERVABLE]) {\n makeObservable(instance);\n }\n if(markInfo[MARK_AS_MOBX_AUTO_OBSERVABLE]) {\n makeAutoObservable(instance);\n }\n return instance;\n }\n }\n );\n ref.current = appctx;\n }\n return React.createElement(\n IoCContext.Provider,\n {\n value: ref.current\n },\n props.children\n );\n}\n\nexport function useService(ctor: Newable): T {\n const ctx = useContext(IoCContext);\n if (!ctx) {\n throw new Error(' has not been applied to the component.');\n }\n return ctx.getInstance(ctor);\n}\n\nexport function renderObserver(render: () => React.ReactElement) {\n return React.createElement(\n Observer,\n {\n render: render\n },\n []\n ) as React.ReactElement\n}\n\nexport * from '@vgerbot/ioc';\n"],"names":["IoCContext","React","createContext","undefined","MARK_AS_MOBX_OBSERVABLE","MARK_AS_MOBX_AUTO_OBSERVABLE","Mark","props","ref","useRef","current","appctx_1","ApplicationContext","callback","registerInstAwareProcessor","class_1","prototype","afterInstantiation","instance","markInfo","getClassMetadata","constructor","getCtorMarkInfo","makeObservable","makeAutoObservable","createElement","Provider","value","children","render","Observer","ctor","ctx","useContext","Error","getInstance"],"mappings":"maAOA,IAAMA,EAAaC,EAAMC,mBAA8CC,GAEjEC,EAA0B,0BAE1BC,EAA+B,6DAOjC,OAAOC,EAAIA,KAACD,GAA8B,UAOxC,SAAcE,GAChB,IAAMC,EAAMC,EAAAA,SACZ,IAAKD,EAAIE,QAAS,CACd,IAAMC,EAAS,IAAIC,EAAAA,mBACW,mBAAnBL,EAAMM,UACbN,EAAMM,SAASF,GAEnBA,EAAOG,2BAA0B,WAC7B,SAAAC,KAWA,OAVIA,EAAkBC,UAAAC,mBAAlB,SAAqCC,GACjC,IAAMC,EAAWR,EAAOS,iBAAiBF,EAASG,aAA2BC,kBAO7E,OANIH,EAASf,IACTmB,EAAcA,eAACL,GAEhBC,EAASd,IACRmB,EAAkBA,mBAACN,GAEhBA,GAEdH,EAZ4B,IAcjCP,EAAIE,QAAUC,EAElB,OAAOV,EAAMwB,cACTzB,EAAW0B,SACX,CACIC,MAAOnB,EAAIE,SAEfH,EAAMqB,mCAvCV,OAAOtB,EAAIA,KAACF,GAAyB,qBAmDnC,SAAyByB,GAC3B,OAAO5B,EAAMwB,cACTK,WACA,CACID,OAAQA,GAEZ,kBAdF,SAAwBE,GAC1B,IAAMC,EAAMC,aAAWjC,GACvB,IAAKgC,EACD,MAAM,IAAIE,MAAM,sDAEpB,OAAOF,EAAIG,YAAYJ"} \ No newline at end of file diff --git a/package.json b/package.json index fe022d4..c98c491 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vgerbot/use-service-react", - "version": "1.0.5", + "version": "1.0.6", "description": "", "main": "dist/index.cjs.js", "module": "dist/index.esm.js", @@ -23,7 +23,8 @@ "lint": " eslint --no-error-on-unmatched-pattern {src,__test__}/**/*.{js,ts,tsx}", "format": "eslint --no-error-on-unmatched-pattern --fix {src,__test__}/**/*.{js,ts,tsx}", "build": "cross-env NODE_ENV=production rollup -c ./rollup.config.js", - "gendoc": "typedoc ./src --out dist/docs --name use-service --hideGenerator" + "gendoc": "typedoc ./src --out dist/docs --name use-service --hideGenerator", + "prepublish": "npm lint && npm run build" }, "lint-staged": { "{src,test}/**/*.{js,ts,tsx}": [