Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 1.3.1 #9

Merged
merged 8 commits into from
May 13, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: action type 的 Symbol 基于方法名
  • Loading branch information
taixw2 committed May 12, 2020
commit 622a80acaae6cf7476568aac3cec4389bddd1be3
34 changes: 16 additions & 18 deletions packages/common/src/helper/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,23 @@ import { TAKE_EVERY, EFFECT_METHODS_META, SymbolType, EFFECT_HELPERS, EFFECT_MET
import { EffectTypeInterface } from '@dxjs/shared/interfaces/dx-effect-type.interface';

export function Effect(actionTypeArg?: SymbolType, helperTypeArg?: any, ...args: any[]): MethodDecorator {
/**
* 参数替换:
* @Effect()
* @Effect(TakeEvery)
* @Effect("actionType", TakeEvery)
* @Effect(Throttle, 350)
* @Effect("actionType", Throttle, 350)
*/
const _defaultActionType = Symbol('__action_type');
let _actionType = actionTypeArg ?? _defaultActionType;
let _helperType = helperTypeArg ?? TAKE_EVERY;

if (EFFECT_HELPERS.includes(actionTypeArg!)) {
if (helperTypeArg) args.unshift(helperTypeArg);
[_actionType, _helperType] = [_defaultActionType, actionTypeArg!];
}

return (target: any, key: SymbolType, descriptor: TypedPropertyDescriptor<any>): TypedPropertyDescriptor<any> => {
// eslint-disable-next-line prettier/prettier
/**
* 参数替换:
* @Effect()
* @Effect(TakeEvery)
* @Effect("actionType", TakeEvery)
* @Effect(Throttle, 350)
* @Effect("actionType", Throttle, 350)
*/
const _defaultActionType = Symbol(String(key));
let _actionType = actionTypeArg ?? _defaultActionType;
let _helperType = helperTypeArg ?? TAKE_EVERY;

if (EFFECT_HELPERS.includes(actionTypeArg!)) {
if (helperTypeArg) args.unshift(helperTypeArg);
[_actionType, _helperType] = [_defaultActionType, actionTypeArg!];
}

const effectKeys: Set<SymbolType> = Reflect.getMetadata(EFFECT_METHODS_KEY, target.constructor) ?? new Set();
if (effectKeys.has(key)) return descriptor;
Expand Down