Skip to content

Commit

Permalink
feat(@dxjs/core): 在开发环境判断收集器手机的是否为空
Browse files Browse the repository at this point in the history
  • Loading branch information
taixw2 committed Apr 15, 2020
1 parent fa23c18 commit 5942605
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/core/src/dx/exports/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@
import { DxModelContstructor } from '@dxjs/shared/interfaces/dx-model.interface';
import { MODEL_NAME } from '@dxjs/shared/symbol';
import { store } from '../../helper/store';
import { DxModel } from '../../dx-model/model';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-var-requires
const invariant = require('invariant');

export function collectFactory(inst: symbol) {
return (name: string) => {
return (name?: string) => {
return function Decorate(ModelTarget: DxModelContstructor): DxModelContstructor {
if (process.env.NODE_ENV === 'development') {
invariant(
ModelTarget instanceof DxModel,
'collect model 必须继承自 DxModel, 当前 model 类型为 %s',
typeof ModelTarget,
);
}

const models = store.getModels(inst);
const _name = name || ModelTarget.name;
Reflect.defineMetadata(MODEL_NAME, _name, ModelTarget);
Expand Down

0 comments on commit 5942605

Please sign in to comment.