diff --git a/package.json b/package.json index 424809d..c40142e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "reto", - "version": "0.4.0", + "version": "0.4.1", "main": "index.js", "repository": "https://github.com/awmleer/reto", "description": "React store with hooks.", @@ -37,6 +37,5 @@ "typescript": "^3.4.5" }, "dependencies": { - "reflect-metadata": "^0.1.12" } } diff --git a/rollup.config.js b/rollup.config.js index c5d7353..b6f4051 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,7 +1,6 @@ module.exports = { external: [ 'react', - 'reflect-metadata', ], input: 'lib/index.js', output: { diff --git a/src/consumer.tsx b/src/consumer.tsx index cccf072..e7df19a 100644 --- a/src/consumer.tsx +++ b/src/consumer.tsx @@ -1,6 +1,7 @@ import * as React from 'react' import {ReactNode, useContext, useDebugValue} from 'react' import {ReactElement} from 'react' +import {contextMap} from './shared-map' import {Store} from './store' import {contextSymbol} from './symbols' @@ -15,7 +16,7 @@ export function Consumer(props: Props) { } export function useStore(S: Store, optional?: boolean) { - const Context = Reflect.getMetadata(contextSymbol, S) + const Context = contextMap.get(S) // Reflect.getMetadata(contextSymbol, S) if (!Context) { if (!optional) { console.error(`No store context of "${S.name}" found. Did you provide it?`) diff --git a/src/index.ts b/src/index.ts index 75b29eb..bf23366 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,3 @@ -import 'reflect-metadata' - export {useStore, Consumer} from './consumer' export {Provider, ProviderProps, withProvider} from './provider' export {Store} from './store' diff --git a/src/provider.tsx b/src/provider.tsx index fdcf536..991c606 100644 --- a/src/provider.tsx +++ b/src/provider.tsx @@ -1,6 +1,7 @@ import * as React from 'react' import {forwardRef, MutableRefObject, ReactNode, useCallback, useRef, useState} from 'react' import {MemoChildren} from './memo-children' +import {contextMap} from './shared-map' import {StateBox} from './state-box' import {Store} from './store' import {contextSymbol} from './symbols' @@ -28,10 +29,10 @@ export const Provider = forwardRef(function Provider(props: Props, ref: Mu updateRef.current = true } - let Context = Reflect.getMetadata(contextSymbol, props.of) + let Context = contextMap.get(props.of) //Reflect.getMetadata(contextSymbol, props.of) if (!Context) { Context = React.createContext(null) - Reflect.defineMetadata(contextSymbol, Context, props.of) + contextMap.set(props.of, Context) //Reflect.defineMetadata(contextSymbol, Context, props.of) } const onReactorChange = useCallback(function(value) { diff --git a/src/shared-map.ts b/src/shared-map.ts new file mode 100644 index 0000000..2dcf277 --- /dev/null +++ b/src/shared-map.ts @@ -0,0 +1,4 @@ +import {Context} from 'react' +import {Store} from './store' + +export const contextMap = new Map, Context>() diff --git a/yarn.lock b/yarn.lock index c5b9812..feccddd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4067,11 +4067,6 @@ redent@^3.0.0: indent-string "^4.0.0" strip-indent "^3.0.0" -reflect-metadata@^0.1.12: - version "0.1.13" - resolved "https://registry.npm.taobao.org/reflect-metadata/download/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08" - integrity sha1-Z648pXyXKiqhZCsQ/jY/4y1J3Ag= - regenerator-runtime@^0.13.2: version "0.13.3" resolved "https://registry.npm.taobao.org/regenerator-runtime/download/regenerator-runtime-0.13.3.tgz#7cf6a77d8f5c6f60eb73c5fc1955b2ceb01e6bf5"