From 7f0fe9aefeb7fdd57e6b742bd901766cdf14a8f2 Mon Sep 17 00:00:00 2001 From: y1j2x34 Date: Mon, 11 Dec 2023 17:13:37 +0800 Subject: [PATCH] feat: release 1.0.7 --- dist/index.cjs.js | 2 +- dist/index.cjs.js.map | 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 | 2 +- src/index.ts | 3 +-- 8 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dist/index.cjs.js b/dist/index.cjs.js index 3195b06..893111d 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"),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]}})})); +"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 a545693..21d9cc4 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 { 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 +{"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 ) 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,wBAZd,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.esm.js b/dist/index.esm.js index 8ae499c..3f684b5 100644 --- a/dist/index.esm.js +++ b/dist/index.esm.js @@ -1,2 +1,2 @@ -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}; +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 58d0981..fc0d7f2 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 { 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 +{"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 ) 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"} \ No newline at end of file diff --git a/dist/index.umd.js b/dist/index.umd.js index 6a8b2fb..75964e1 100644 --- a/dist/index.umd.js +++ b/dist/index.umd.js @@ -1,2 +1,2 @@ -!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]}})}))})); +!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 3f7882b..9a262f2 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 { 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 +{"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 ) 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,kBAZd,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 c98c491..2e66690 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@vgerbot/use-service-react", - "version": "1.0.6", + "version": "1.0.7", "description": "", "main": "dist/index.cjs.js", "module": "dist/index.esm.js", diff --git a/src/index.ts b/src/index.ts index 7d5d0e1..59f7135 100644 --- a/src/index.ts +++ b/src/index.ts @@ -68,8 +68,7 @@ export function renderObserver(render: () => React.ReactElement) { Observer, { render: render - }, - [] + } ) as React.ReactElement }