@mic-rexjs/usecases
Version:
Usecases of Clean Architecture
57 lines (56 loc) • 1.7 kB
JavaScript
import { entityUseCase } from '../entityUseCase';
export const arrayUseCase = () => {
const entityReducers = entityUseCase();
const extractEntity = (entity, filter) => {
return entity.filter(filter);
};
const fillEntity = function* (entity, value, start, end) {
const newEntity = entity.slice();
newEntity.fill(value, start, end);
return yield newEntity;
};
const filterEntity = function* (entity, filter) {
return yield entity.filter(filter);
};
const popEntity = function* (entity) {
const newEntity = entity.slice();
const item = newEntity.pop();
yield newEntity;
return item;
};
const pushEntity = function* (entity, ...items) {
const newEntity = [...entity, ...items];
const { length } = newEntity;
yield newEntity;
return length;
};
const shiftEntity = function* (entity) {
const newEntity = entity.slice();
const item = newEntity.shift();
yield newEntity;
return item;
};
const spliceEntity = function* (entity, ...args) {
const newEntity = entity.slice();
const splicedItems = newEntity.splice(...args);
yield newEntity;
return splicedItems;
};
const unshiftEntity = function* (entity, ...items) {
const newEntity = [...items, ...entity];
const { length } = newEntity;
yield newEntity;
return length;
};
return {
...entityReducers,
extractEntity,
fillEntity,
filterEntity,
popEntity,
pushEntity,
shiftEntity,
spliceEntity,
unshiftEntity,
};
};