Skip to content

Commit

Permalink
chore: fix some lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepolischuk committed Apr 3, 2024
1 parent 2b58d83 commit 0678814
Show file tree
Hide file tree
Showing 19 changed files with 156 additions and 153 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"redux": "^4",
"size-limit": "^11.1.2",
"ts-jest": "^29.1.2",
Expand Down
11 changes: 3 additions & 8 deletions packages/core-v1/lib/Bite.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import type {MakeBiteProcessorType, MakeBiteReducerType} from './types';

export const Bite: BiteType = (reducer, processor) => ({reducer, processor});

export type BiteType = <
ITriggers,
IState,
K extends keyof ITriggers,
IRootTrigger,
>(
type BiteType = <ITriggers, IState, K extends keyof ITriggers, IRootTrigger>(
reducer: MakeBiteReducerType<ITriggers, IRootTrigger, IState, K>,
processor: MakeBiteProcessorType<ITriggers, IRootTrigger, K>,
) => {
reducer: MakeBiteReducerType<ITriggers, IRootTrigger, IState, K>;
processor: MakeBiteProcessorType<ITriggers, IRootTrigger, K>;
};

export const Bite: BiteType = (reducer, processor) => ({reducer, processor});
8 changes: 6 additions & 2 deletions packages/core-v1/lib/System.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,16 @@ export class System {
return arr.length > 1 ? arr[1] : null;
};

public addWait = (trigger: string, {resolve, reject, args}, timeout) => {
public addWait = (
trigger: string,
{resolve, reject, args},
timeout = 5000,
) => {
const timeOutId = setTimeout(() => {
if (this.waits[trigger]) {
this.waits[trigger].reject(`${trigger} TIMEOUT`);
}
}, timeout || 5000);
}, timeout);

this.waits[trigger] = {resolve, reject, args, id: timeOutId};
};
Expand Down
129 changes: 66 additions & 63 deletions packages/core-v1/lib/createMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,84 +18,87 @@ export const makeProcMiddleware = (
): Middleware => {

Check failure on line 18 in packages/core-v1/lib/createMiddleware.ts

View workflow job for this annotation

GitHub Actions / lint

Arrow function has too many parameters (5). Maximum allowed is 3
const system = useSystem();

return (store) => (next) => (action) => {
let ignore = false;
let forceStopPropagate = false;
const sourceSlice = action.sourceSlice;
const actionType = action.type;
const isBiteHit = matchBiteName(configs, actionType);
const handleInit = (store, actionType, actionPayload, skipInit) => {

Check failure on line 21 in packages/core-v1/lib/createMiddleware.ts

View workflow job for this annotation

GitHub Actions / lint

Arrow function has too many parameters (4). Maximum allowed is 3
const initConfig = matchInitTrigger(configs, actionType);

if (sliceConfig?.ignoreExternal) {
if (sliceConfig.ignoreExternal === 'ignoreAll') {
ignore = true;
} else if (
sourceSlice &&
sliceConfig.ignoreExternal.length &&
sliceConfig.ignoreExternal.indexOf(sourceSlice) !== -1
) {
ignore = true;
}
if (!initConfig || skipInit) {
return;
}

const actionPayload = action.payload || null;
const nexio = (args) => {
system.taksQueue.setCurrentTask(action);
const opts = prepareOpts(initConfig, store, system, sliceName, injected);
const instance = createProcessorInstance(
system,
initConfig.config,
opts,
actionType,
);

return next(args);
};
if (instance) {
onInit(instance, actionPayload);
}

if (isBiteHit && ignore) {
return next(action);
if (instance?.watchAfter) {
system.afterHandlers.push(() => instance.watchAfter);
}
};

const handleUpdate = (store, action, skipUpdate) => {
if (skipUpdate) {
return false;
}

const skipInit = action.opts && action.opts.noInit;
const skipUpdate = action.opts && action.opts.noUpdate;
const initConfig = matchInitTrigger(configs, actionType); /// Возвращает 1 конфиг
const updateConfigs = matchUpdateTrigger(configs, actionType); //Возвращает массив конфигов

if (initConfig && !skipInit) {
const opts = prepareOpts(initConfig, store, system, sliceName, injected);
const instance = createProcessorInstance(
system,
initConfig.config,
opts,
actionType,
const updateConfigs = matchUpdateTrigger(configs, action.type);

return updateConfigs.reduce((forceStopPropagate, config) => {
const instances = getInstance(config.config, config.trigger, system);

return (
forceStopPropagate ||
instances.some(
(instance) =>
!BeforeUpdate(

Check failure on line 59 in packages/core-v1/lib/createMiddleware.ts

View workflow job for this annotation

GitHub Actions / lint

A function with a name starting with an uppercase letter should only be used as a constructor
instance,
store.getState(),
action,
reducers,
sliceName,
),
)
);
}, false);
};

if (instance) {
onInit(instance, actionPayload);
}
return (store) => (next) => (action) => {
const {
sourceSlice,
type: actionType,
payload: actionPayload,
opts,
} = action;
const isBiteHit = matchBiteName(configs, actionType);
const ignore =
sliceConfig?.ignoreExternal &&
(sliceConfig.ignoreExternal === 'ignoreAll' ||
(sourceSlice &&
sliceConfig.ignoreExternal.length &&
sliceConfig.ignoreExternal.includes(sourceSlice)));

if (instance.watchAfter) {
// get list of events form config
// check if contains then call
system.afterHandlers.push(() => instance.watchAfter);
}
if (isBiteHit && ignore) {
return next(action);
}

if (updateConfigs.length && !skipUpdate) {
updateConfigs.forEach((c) => {
const instances = getInstance(c.config, c.trigger, system);

instances.forEach((i) => {
const proppagate = BeforeUpdate(
i,
store.getState(),
action,
reducers,
sliceName,
);

if (!proppagate) {
forceStopPropagate = true;
}
});
});
}
handleInit(store, actionType, actionPayload, opts?.noInit);

const forceStopPropagate = handleUpdate(store, action, opts?.noUpdate);
const processorOpts = system.getProcessorInfo(action.type);

system.resolveWait(action.type, action.payload);
system.resolveWait(action.type, actionPayload);

const nexio = (args) => {
system.taksQueue.setCurrentTask(action);

return next(args);
};

return forceStopPropagate ||
(isBiteHit && processorOpts && !processorOpts.propagate)
Expand Down
16 changes: 6 additions & 10 deletions packages/core-v1/lib/createReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ export function makeReducer<AC, StoreType>(
state: StoreType = initialState,
action: {type: string; payload: unknown},
) {
const parts = action.type.split('/');
const [trigger, status] = [parts[0], parts[1]];
const [trigger, status] = action.type.split('/');
const reducer = reducers[trigger];

if (!status) {
if (reducers[trigger]) {
if (typeof reducers[trigger] === 'function') {
return makeImmutable(state, action.payload, reducers[trigger]);
}
}
} else if (reducers[trigger]) {
if (reducers[trigger][status]) {
return makeImmutable(state, action.payload, reducers[trigger][status]);
if (typeof reducer === 'function') {
return makeImmutable(state, action.payload, reducer);
}
} else if (reducer?.[status]) {
return makeImmutable(state, action.payload, reducer[status]);
}

return state;
Expand Down
12 changes: 6 additions & 6 deletions packages/core-v1/lib/processor/createProcessorInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export function createProcessorInstance(
}

function multipleMode(system, config, opt, actionType) {

Check failure on line 25 in packages/core-v1/lib/processor/createProcessorInstance.ts

View workflow job for this annotation

GitHub Actions / lint

Function 'multipleMode' has too many parameters (4). Maximum allowed is 3
const processor = config.script;
const newInstance = new processor(opt);
const Processor = config.script;
const newInstance = new Processor(opt);
const processUid = opt.uid;

system.upProcess(newInstance, actionType, processUid);
Expand All @@ -33,31 +33,31 @@ function multipleMode(system, config, opt, actionType) {
}

function stableMode(system, config, opt, actionType) {

Check failure on line 35 in packages/core-v1/lib/processor/createProcessorInstance.ts

View workflow job for this annotation

GitHub Actions / lint

Function 'stableMode' has too many parameters (4). Maximum allowed is 3
const processor = config.script;
const Processor = config.script;
const processUid = opt.uid;
const found = system.findProcess(actionType);

if (found.length) {
return found[0];
}

const newInstance = new processor(opt);
const newInstance = new Processor(opt);

system.upProcess(newInstance, actionType, processUid);

return newInstance; //.init(actionPayload);
}

function refreshingMode(system, config, opt, actionType) {

Check failure on line 51 in packages/core-v1/lib/processor/createProcessorInstance.ts

View workflow job for this annotation

GitHub Actions / lint

Function 'refreshingMode' has too many parameters (4). Maximum allowed is 3
const processor = config.script;
const Processor = config.script;
const found = system.findProcess(actionType);
const processUid = opt.uid;

if (found) {
system.downProcess(actionType);
}

const newInstance = new processor(opt);
const newInstance = new Processor(opt);

system.upProcess(newInstance, actionType, processUid);

Expand Down
5 changes: 2 additions & 3 deletions packages/core-v1/lib/processor/lifecycle/Update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ export function BeforeUpdate(instance, state, action, reducers, sliceName) {
const actionType = action.type;
const actionPayload = action.payload;
let propagate = true;
let keepUpdate = false;
const stopPropagate = (args?: {keepUpdate: boolean}) => {
keepUpdate = (args && args.keepUpdate) || false;

const stopPropagate = () => {
propagate = false;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/core-v1/lib/processor/matchBiteName.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getTriggerAndStatus} from '../utils';

export function matchBiteName(config, actionType) {
const {trigger, status} = getTriggerAndStatus(actionType);
const {trigger} = getTriggerAndStatus(actionType);

return Boolean(config[trigger]);
}
11 changes: 4 additions & 7 deletions packages/core-v1/lib/processor/matchInitTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import {getTriggerAndStatus} from '../utils';

export function matchInitTrigger(config, actionType) {
export function matchInitTrigger(configs, actionType) {
const {trigger, status} = getTriggerAndStatus(actionType);
const config = configs[trigger];

if (config[trigger]) {
if (!config[trigger].initOn) {
return {config: config[trigger], trigger};
} else if (config[trigger] && config[trigger].initOn === status) {
return {config: config[trigger], trigger};
}
if (config && (!config.initOn || config.initOn === status)) {
return {config, trigger};
}

return null;
Expand Down
24 changes: 10 additions & 14 deletions packages/core-v1/lib/processor/matchUpdateTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,22 @@ export function matchUpdateTrigger(configs, actionType) {
}

const matchedTrigger = watchScope.find((t) => {
const firstKey = Object.keys(t)[0];
const [firstKey] = Object.keys(t);

return t === trigger || firstKey === trigger;
});

if (matchedTrigger) {
if (typeof matchedTrigger === 'string') {
return true;
} else if (
matchedTrigger[Object.keys(matchedTrigger)[0]] === status
if (typeof matchedTrigger === 'string') {
return true;
} else if (matchedTrigger) {
const [firstKey] = Object.keys(matchedTrigger);
const matchedStatus = matchedTrigger[firstKey];

if (
matchedStatus === status ||
(Array.isArray(matchedStatus) && matchedStatus.includes(status))
) {
return true;
} else if (
Array.isArray(matchedTrigger[Object.keys(matchedTrigger)[0]])
) {
if (
matchedTrigger[Object.keys(matchedTrigger)[0]].includes(status)
) {
return true;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/core-v1/lib/processor/opts/save.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {getActionType} from '../../utils';

// eslint-disable-next-line import/no-unused-modules
export function Save(store, config, system, uid) {
//const canTrigger = config.config.canTrigger;

Expand Down
1 change: 1 addition & 0 deletions packages/core-v1/lib/processor/opts/triggerOnly.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {getActionType} from '../../utils';

// eslint-disable-next-line import/no-unused-modules
export function TriggerOnly(store, config, system, uid) {
//const canTrigger = config.config.canTrigger;

Expand Down
2 changes: 1 addition & 1 deletion packages/core-v1/lib/processor/opts/wait.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getActionType} from '../../utils';

export function Wait(store, config, system, uid) {
export function Wait(store, config, system, _uid) {
//const canTrigger = config.config.canTrigger;

return (actionType, actionStatus, timeout) => {
Expand Down
Loading

0 comments on commit 0678814

Please sign in to comment.