Skip to content

Commit

Permalink
remove reflect-metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
awmleer committed Oct 25, 2019
1 parent 8873fc5 commit 4762a00
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 13 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down Expand Up @@ -37,6 +37,5 @@
"typescript": "^3.4.5"
},
"dependencies": {
"reflect-metadata": "^0.1.12"
}
}
1 change: 0 additions & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
external: [
'react',
'reflect-metadata',
],
input: 'lib/index.js',
output: {
Expand Down
3 changes: 2 additions & 1 deletion src/consumer.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -15,7 +16,7 @@ export function Consumer<T>(props: Props<T>) {
}

export function useStore<T>(S: Store<T>, 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?`)
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'reflect-metadata'

export {useStore, Consumer} from './consumer'
export {Provider, ProviderProps, withProvider} from './provider'
export {Store} from './store'
5 changes: 3 additions & 2 deletions src/provider.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -28,10 +29,10 @@ export const Provider = forwardRef(function Provider<T>(props: Props<T>, 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) {
Expand Down
4 changes: 4 additions & 0 deletions src/shared-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {Context} from 'react'
import {Store} from './store'

export const contextMap = new Map<Store<any>, Context<any>>()
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4762a00

Please sign in to comment.