0.2.37 • Published 2 years ago

@infini-soft/useoperationfactory v0.2.37

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

⚡ Getting started

One of the most important foundation of our tools is useOperationFactory React hook. As tiny as (5k) 49 lines of code to cover almost any implementation possible for error management, UI Feedback, logging, transitions, timeouts, errors, success, debounce, flow control, micro state management or any requirements.

Combined with @infini-soft/ic-hub-core, acting as pub/sub hub, it's possible for compose complex pattern for any use cases at scale.

✨ Features

  • Strongly typed
  • Scalable

📚 Documentation

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

📦 Install

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

🔨 Usage

import React from 'react';
import { HubCore, consolePlugin } from '@infini-soft/ic-hub-core';
import { useOperationFactory } from '@infini-soft/useoperationfactory';

const mockOperation = () =>
  new Promise<string>((resolve, reject) => {
    resolve('Mocked data');
  });

  const mockFailOperation = () =>
  new Promise<string>((resolve, reject) => {
    reject('Failed operation');
  });

const hub = new HubCore();
hub.register(consolePlugin);

export default () => {
  const { run, result, status, isSuccess, isLoading, isError, errorDetails } = useOperationFactory(
    mockOperation,
    { hub },
  );

    const fail = useOperationFactory(
    mockFailOperation,
    { hub },
  );

  return (
    <div className="container">
      <div className="tests">
        <h1>Success</h1>

        <div>Status = {status}</div>
        <div>Loading = {String(isLoading)}</div>
        <div>Result = {result && isSuccess && JSON.stringify(result)}</div>

        <button onClick={run}>Test</button>
      </div>

      <div className="tests">
        <h1>Error</h1>

        <div>Status = {fail.status}</div>
        <div>Loading = {String(fail.isLoading)}</div>
        <div>Result = {fail.result && JSON.stringify(result)}</div>
        <div>Error = {String(fail.isError)}</div>
        <div>Error details = {fail.isError && String(fail.errorDetails)}</div>

        <button onClick={fail.run}>Test</button>
      </div>
    </div>
  );
};

Powered 🚀 by Infinisoft Inc. Wanna cook a batch with the trailer park boys? come in the kitchen https://www.kitchen.infini-soft.com

0.2.37

2 years ago

0.2.36

2 years ago

0.2.35

2 years ago

0.2.34

2 years ago

0.2.33

2 years ago

0.2.32

2 years ago

0.2.31

2 years ago

0.2.30

2 years ago

0.2.29

2 years ago

0.2.28

2 years ago

0.2.27

2 years ago

0.2.26

2 years ago

0.2.25

2 years ago

0.2.24

2 years ago

0.2.23

2 years ago

0.2.22

2 years ago

0.2.21

2 years ago

0.2.20

2 years ago

0.2.19

2 years ago

0.2.18

2 years ago

0.2.17

2 years ago

0.2.16

2 years ago

0.2.15

2 years ago

0.2.14

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.42

2 years ago

0.0.41

2 years ago

0.0.38

2 years ago

0.0.37

2 years ago

0.0.34

2 years ago

0.0.33

2 years ago

0.0.31

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago