0.1.43 • Published 3 years ago

@infini-soft/usecrudfactory v0.1.43

Weekly downloads
-
License
MIT
Repository
github
Last release
3 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

3 years ago

0.1.42

3 years ago

0.1.43

3 years ago

0.1.40

3 years ago

0.1.39

3 years ago

0.1.38

3 years ago

0.1.37

3 years ago

0.1.36

3 years ago

0.1.35

3 years ago

0.1.34

3 years ago

0.1.33

3 years ago

0.1.32

3 years ago

0.1.31

3 years ago

0.1.30

3 years ago

0.1.29

3 years ago

0.1.28

3 years ago

0.1.27

3 years ago

0.1.26

3 years ago

0.1.25

3 years ago

0.1.24

3 years ago

0.1.23

3 years ago

0.1.22

3 years ago

0.1.21

3 years ago

0.1.20

3 years ago

0.1.19

3 years ago

0.1.18

3 years ago

0.1.17

3 years ago

0.1.16

3 years ago

0.1.15

3 years ago

0.1.14

3 years ago

0.1.13

3 years ago

0.1.12

3 years ago

0.1.11

3 years ago

0.1.10

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.8

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago