@gecut/lit-helper
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

Gecut Data Manager

Receiver Concept

receiver of data and cache on memory ram and update

Sender Concept

sender of data and update dependencies data, for example when create new todo, should update todo list data

How can i use ?

step by step to use @gecut/data-manager

First Step

define type of receivers and senders

declare global {
  interface GecutReceiverServices {
    readonly 'todo-storage': TodoInterface[];
  }
  interface GecutSenderServices {
    readonly 'new-todo': TodoInterface;
  }
}

Second Step

define dataManager from a new instance of DataManager class

const dataManager = new DataManager(
  {
    'todo-storage': {
      receiverFunction() {
        // receive todo-storage data and return
        return api.storage.query();
      },
    },
  },
  {
    'new-todo': {
      // when send data update todo-storage
      dependencies: ['todo-storage'],
      async senderFunction(newTodo) {
        // send new todo data to back-end
        await api.new.mutate(newTodo);
      },
    },
  },
);

Third Step

// define this in Component Class and use
// receiver decorator has autoUpdate (automatic requestUpdate)
@receiver('todo-storage', dataManager)
todoStorage!: TodoInterface[];

Fourth Step

// use this for send data
dataManager.senders['new-todo']?.send({
  status: true,
  message: textInputValue,
});

Readme

Keywords

Package Sidebar

Install

npm i @gecut/lit-helper

Weekly Downloads

101

Version

2.1.1

License

MIT

Unpacked Size

162 kB

Total Files

76

Last publish

Collaborators

  • mm25zamanian