0.1.43 • Published 2 years ago

@infini-soft/usecrudfactory v0.1.43

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

🏭 README useCrudFactory


Idiomatic React Hook CRUD SDK Factory.

✨ Features

  • Generate CRUD Sdk
  • React hook
  • Execute multiple stateful operation simultaneously
  • Typescript / Javascript
  • Very tiny (11k)

📚 Documentation

Get all documentations, examples and execute it directly from our website, the ☕ kitchen! Come cook software :) https://www.kitchen.infini-soft.com/hooks/crudfactory

Getting started


📦 Install

$ npm install @infini-soft/usecrudfactory --save
# or
$ yarn add @infini-soft/usecrudfactory

🕳️ Mock Services

We will use these fake services for the example.

// example.implementation.tsx
import { useCrudFactory } from '@infini-soft/usecrudfactory'
import { Operation } from '@infini-soft/useoperationfactory';

export const createService: Operation<
 [string, { name: string }],
 Promise<{ success: boolean; message: string }>
> = (...arg) =>
 new Promise((res, rej) => {
   res({ success: true, message: 'Success' });
 });

export const readService: Operation<[string], Promise<string>> = (a) =>
 new Promise((res, rej) => {
   res(`Item was read`);
 });

export const updateService: Operation<[string], Promise<string>> = (a) =>
 new Promise((res, rej) => {
   res(`Item was updated`);
 });

export const deleteService: Operation<[string], Promise<boolean>> = (a) =>
 new Promise((res, rej) => {
   res(true);
 });

export const listService: Operation<[string], Promise<string[]>> = (a) =>
 new Promise<string[]>((res, rej) => {
   res(['item1', 'item2']);
 });

💎 Implementation

// useMySdk.tsx
import React from 'react';
import { useCrudFactory } from '@infini-soft/useCrudFactory';
import * as services from './example.implementation.tsx';

export const useMyCrudSdk = () => {
  const sdk = useCrudFactory(services);

  // Your implementation

  return sdk;
};

🎁 My Sdk

// example.tsx
import React from 'react';
import { useMySdk } from './useMySdk';

export default () => {
 const { create, read, list } = useMySdk();

 const handleRunAll = () => {
   create.run();
   read.run();
   list.run();
 };

 return (
   <>
     <div className="container-vertical">
       <h1>Hello useCrudFactory</h1>
       <button onClick={handleRunAll}>Run all</button>
     </div>
     <div className="container">
       <div className="tests">
         <h2>Create</h2>
         <ul>
           <li>Status = {String(create.status)}</li>
           <li>Data = {JSON.stringify(create.data)}</li>
         </ul>
         <button onClick={create.run}>Create Test</button>
       </div>

       <div className="tests">
         <h2>Read</h2>
         <ul>
           <li>Status = {String(read.status)}</li>
           <li>Data = {String(read.data)}</li>
         </ul>
         <button onClick={read.run}>Read Test</button>
       </div>

       <div className="tests">
         <h2>List</h2>
         <ul>
           <li>Status = {String(list.status)}</li>
           <li>Data = {String(list.data)}</li>
         </ul>
         <button onClick={list.run}>List Test</button>
       </div>
     </div>
   </>
 );
};

Powered 🚀 by Infinisoft Inc. Wanna cook the future? Come in the kitchen https://www.kitchen.infini-soft.com

0.1.41

2 years ago

0.1.42

2 years ago

0.1.43

2 years ago

0.1.40

2 years ago

0.1.39

2 years ago

0.1.38

2 years ago

0.1.37

2 years ago

0.1.36

2 years ago

0.1.35

2 years ago

0.1.34

2 years ago

0.1.33

2 years ago

0.1.32

2 years ago

0.1.31

2 years ago

0.1.30

2 years ago

0.1.29

2 years ago

0.1.28

2 years ago

0.1.27

2 years ago

0.1.26

2 years ago

0.1.25

2 years ago

0.1.24

2 years ago

0.1.23

2 years ago

0.1.22

2 years ago

0.1.21

2 years ago

0.1.20

2 years ago

0.1.19

2 years ago

0.1.18

2 years ago

0.1.17

2 years ago

0.1.16

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.0

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.8

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago