reactive-di
Advanced tools
Comparing version 2.0.2 to 2.0.3
'use strict'; | ||
exports.__esModule = true; | ||
exports.getMeta = getMeta; | ||
exports.RdiMeta = exports.metaKey = exports.functionTypesKey = exports.paramTypesKey = undefined; | ||
exports.component = component; | ||
@@ -13,7 +13,14 @@ exports.deps = deps; | ||
var _CustomReflect = require('./CustomReflect'); | ||
var _CustomReflect2 = _interopRequireDefault(_CustomReflect); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
/*:: import type {DepFn, Key, DepDict, ArgDep, DepAlias, RegisterDepItem} from './interfaces/deps'*/ | ||
var paramTypesKey /*: Symbol*/ = exports.paramTypesKey = Symbol.for('design:paramtypes'); | ||
var metaKey /*: Symbol*/ = exports.metaKey = Symbol.for('rdi:meta'); | ||
var paramTypesKey /*: string*/ = exports.paramTypesKey = 'design:paramtypes'; | ||
var functionTypesKey /*: string*/ = exports.functionTypesKey = 'design:function'; | ||
var metaKey /*: string*/ = exports.metaKey = 'rdi:meta'; | ||
@@ -31,10 +38,13 @@ var RdiMeta = exports.RdiMeta = function RdiMeta /*:: <V>*/() { | ||
this.localDeps = null; | ||
this.isFactory = false; | ||
this.updaters = null; | ||
}; | ||
var dm = _CustomReflect2.default.defineMetadata; | ||
var gm = _CustomReflect2.default.getMetadata; | ||
function getMeta /*:: <V: Function>*/(target /*: V*/) /*: RdiMeta<*>*/ { | ||
var meta /*: ?RdiMeta<*>*/ = target[metaKey]; | ||
var meta /*: ?RdiMeta<*>*/ = gm(metaKey, target); | ||
if (!meta) { | ||
meta = target[metaKey] = new RdiMeta(); | ||
meta = new RdiMeta(); | ||
dm(metaKey, meta, target); | ||
} | ||
@@ -66,3 +76,3 @@ return meta; | ||
if (args.length) { | ||
target[paramTypesKey] = args; | ||
dm(paramTypesKey, args, target); | ||
} | ||
@@ -74,3 +84,3 @@ return target; | ||
function factory /*:: <V: Function>*/(target /*: V*/) /*: V*/ { | ||
getMeta(target).isFactory = true; | ||
dm(functionTypesKey, true, target); | ||
return target; | ||
@@ -77,0 +87,0 @@ } |
@@ -27,2 +27,6 @@ 'use strict'; | ||
var _CustomReflect = require('./CustomReflect'); | ||
var _CustomReflect2 = _interopRequireDefault(_CustomReflect); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -47,3 +51,3 @@ | ||
/*:: type CacheMap = Map<Function|string, Derivable<any>>*/ | ||
/*:: type Meta = [Function, ArgDep[], RdiMeta<*>]*/ | ||
/*:: type Meta = [Function, ArgDep[], RdiMeta<*>, boolean]*/ | ||
@@ -53,4 +57,8 @@ | ||
var defaultArr /*: ArgDep[]*/ = []; | ||
var gm = _CustomReflect2.default.getMetadata; | ||
function metaFromTarget(target /*: Function*/) /*: Meta*/ { | ||
return [target, target[_annotations.paramTypesKey] || [], target[_annotations.metaKey] || defaultMeta]; | ||
return [target, gm(_annotations.paramTypesKey, target) || defaultArr, gm(_annotations.metaKey, target) || defaultMeta, gm(_annotations.functionTypesKey, target) || false]; | ||
} | ||
@@ -218,2 +226,3 @@ | ||
var meta = _getMeta[2]; | ||
var isFactory = _getMeta[3]; | ||
@@ -268,3 +277,3 @@ this._path.push((0, _debugName2.default)(key)); | ||
var preprocess /*: (v: any) => any*/ = meta.isTheme ? this.__createSheet : passAny; | ||
if (meta.isFactory) { | ||
if (isFactory) { | ||
if (meta.writable) { | ||
@@ -271,0 +280,0 @@ atom = adapter.atom((this._createFactory(target, depsAtom) /*: any*/)); |
{ | ||
"name": "reactive-di", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Reactive dependency injection", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
// @flow | ||
import type {DepFn, Key, DepDict, ArgDep, DepAlias, RegisterDepItem} from './interfaces/deps' | ||
import CustomReflect from './CustomReflect' | ||
export const paramTypesKey: Symbol = Symbol.for('design:paramtypes') | ||
export const metaKey: Symbol = Symbol.for('rdi:meta') | ||
export const paramTypesKey: string = 'design:paramtypes' | ||
export const functionTypesKey: string = 'design:function' | ||
export const metaKey: string = 'rdi:meta' | ||
@@ -16,3 +18,2 @@ export class RdiMeta<V> { | ||
localDeps: ?RegisterDepItem[] = null; | ||
isFactory: boolean = false; | ||
@@ -22,6 +23,10 @@ updaters: ?Key[] = null; | ||
export function getMeta<V: Function>(target: V): RdiMeta<*> { | ||
let meta: ?RdiMeta<*> = target[metaKey] | ||
const dm = CustomReflect.defineMetadata | ||
const gm = CustomReflect.getMetadata | ||
function getMeta<V: Function>(target: V): RdiMeta<*> { | ||
let meta: ?RdiMeta<*> = gm(metaKey, target) | ||
if (!meta) { | ||
meta = target[metaKey] = new RdiMeta() | ||
meta = new RdiMeta() | ||
dm(metaKey, meta, target) | ||
} | ||
@@ -45,3 +50,3 @@ return meta | ||
if (args.length) { | ||
target[paramTypesKey] = args | ||
dm(paramTypesKey, args, target) | ||
} | ||
@@ -53,3 +58,3 @@ return target | ||
export function factory<V: Function>(target: V): V { | ||
getMeta(target).isFactory = true | ||
dm(functionTypesKey, true, target) | ||
return target | ||
@@ -56,0 +61,0 @@ } |
// @flow | ||
import {paramTypesKey, metaKey, RdiMeta} from './annotations' | ||
import {paramTypesKey, functionTypesKey, metaKey, RdiMeta} from './annotations' | ||
import type {IUpdater, IUpdaterStatus} from './interfaces/updater' | ||
@@ -13,2 +13,3 @@ import type {DepFn, Key, RegisterDepItem, DepAlias, ArgDep} from './interfaces/deps' | ||
import UpdaterStatus from './UpdaterStatus' | ||
import CustomReflect from './CustomReflect' | ||
@@ -25,11 +26,16 @@ function passAny<V>(v: V): V { | ||
type Meta = [Function, ArgDep[], RdiMeta<*>] | ||
type Meta = [Function, ArgDep[], RdiMeta<*>, boolean] | ||
const defaultMeta: RdiMeta<*> = new RdiMeta() | ||
const defaultArr: ArgDep[] = [] | ||
const gm = CustomReflect.getMetadata | ||
function metaFromTarget(target: Function): Meta { | ||
return [ | ||
target, | ||
target[paramTypesKey] || [], | ||
target[metaKey] || defaultMeta | ||
gm(paramTypesKey, target) || defaultArr, | ||
gm(metaKey, target) || defaultMeta, | ||
gm(functionTypesKey, target) || false | ||
] | ||
@@ -196,3 +202,3 @@ } | ||
const [target, deps, meta] = this.getMeta(key) | ||
const [target, deps, meta, isFactory] = this.getMeta(key) | ||
this._path.push(debugName(key)) | ||
@@ -248,3 +254,3 @@ const adapter: Adapter = this._adapter | ||
const preprocess: (v: any) => any = meta.isTheme ? this.__createSheet : passAny | ||
if (meta.isFactory) { | ||
if (isFactory) { | ||
if (meta.writable) { | ||
@@ -251,0 +257,0 @@ atom = adapter.atom((this._createFactory(target, depsAtom): any)) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
179689
70
3049