@budarin/tasks-domain
TypeScript icon, indicating that this package has built-in type declarations

1.0.94 • Public • Published

tasks-domain

Contains a description of the entities

  • icon
  • priority
  • task category
  • task

their types, constructors, object extraction and validation methods.

It also describes the structure of storing entities in the application state store and methods for changing them for reuse in various applications.

Data model

Data model

Install

yarn add @budarin/tasks-domain

Usage

import type { TasksStoreState } from '@budarin/tasks-domain';
import { tasksStoreState, initTasksStore } from '@budarin/tasks-domain';

import { storeLogger } from '../app/providers';
import { INBOX_KEY, OVERDUE_KEY, RECYCLE_BIN_KEY } from '../app/entities/index.ts';

type AppState = TasksStoreState && SomeOtherState;

useAppStore = create<AppState>()({
    ...tasksStoreState,

    navigationFilter: {...},

    tasks: {
        ...tasksStoreState.tasks,

        idsByExpireDate: {},
        idsByCategoryId: {},
        idsByFilterId: {
            [INBOX_KEY]: [],
            [RECYCLE_BIN_KEY]: [],
            [OVERDUE_KEY]: [],
        },
    },
});

// you need to initialize store first after creating useAppStore
// with the instance of real store for using in entities methods and with the logger for store
initTasksStore(useAppStore, storeLogger);

extending domain store logic in use cases

import { addTask, createTask } from '@budarin/tasks-domain';

function storeAddTask(task: unknown): ResultOrError<Task> {
    const addResult = addTask(task);

    if (addResult.error) {
        return addResult;
    }

    const state = useAppStore.getState();
    // additional logic for managing filters & categories
    {...}
}

// using extended logic
storeAddTask(createTask({
    taskId: 1,
    title: 'TaskTitle',
    priorityId: 1,
    deleted: false,
    completed: false,
}))

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @budarin/tasks-domain

Weekly Downloads

2

Version

1.0.94

License

MIT

Unpacked Size

134 kB

Total Files

135

Last publish

Collaborators

  • budarin