@sigi/core
Version:
Sigi core library
46 lines • 1.82 kB
JavaScript
var _a, _b;
import { DEFINE_ACTION_DECORATOR_SYMBOL, REDUCER_DECORATOR_SYMBOL, IMMER_REDUCER_DECORATOR_SYMBOL, EFFECT_DECORATOR_SYMBOL, SSR_ACTION_META_SYMBOL, ACTION_TO_SKIP_SYMBOL, } from './symbols';
var actionEnum = {
DefineAction: DEFINE_ACTION_DECORATOR_SYMBOL,
Reducer: REDUCER_DECORATOR_SYMBOL,
ImmerReducer: IMMER_REDUCER_DECORATOR_SYMBOL,
Effect: EFFECT_DECORATOR_SYMBOL,
};
var metadataFactory = function (key) {
var get = function (prototype, defaultValue) {
var meta = Reflect.getMetadata(key, prototype);
if (!meta || !Array.isArray(meta)) {
return defaultValue;
}
return meta;
};
return {
get: get,
add: function (prototype, meta) {
var stored = get(prototype);
if (!stored) {
Reflect.defineMetadata(key, [meta], prototype);
}
else {
stored.push(meta);
}
},
};
};
export function getDecoratedActions(prototype, type, defaultValue) {
var get = metadataFactory(actionEnum[type]).get;
return get(prototype, defaultValue);
}
export function createActionDecorator(type) {
return function () { return function (prototype, propertyKey, descriptor) {
if (typeof prototype === 'function' || !propertyKey) {
throw new Error("".concat(type, " can only be used to decorate properties."));
}
var add = metadataFactory(actionEnum[type]).add;
add(prototype, propertyKey);
return descriptor;
}; };
}
export var getSSREffectMeta = (_a = metadataFactory(SSR_ACTION_META_SYMBOL), _a.get), addSSREffectMeta = _a.add;
export var getActionsToSkip = (_b = metadataFactory(ACTION_TO_SKIP_SYMBOL), _b.get), addActionToSkip = _b.add;
//# sourceMappingURL=metadata.js.map