1.0.5 • Published 11 months ago

@jswork/command-manager v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

command-manager

React command manager.

installation

yarn add @jswork/command-manager

usage

  1. Add provider to root.
import React from 'react';
import ReactDOM from 'react-dom/client';
import { scanVite } from '@jswork/scan-modules';
import ReactCommandManager from '@jswork/command-manager/src/main';

const moduleFiles = import.meta.glob('./shared/commands/*/.ts', { eager: true }); const modules = scanVite(moduleFiles, { modules: '/commands/', });

import App from './app'; import './index.scss';

function App(){ return (

<div>
  <button onClick={() => nx.$exec('posts.create')}>Create</button>
  <button onClick={() => nx.$exec('posts.update', { title: 'new title' })}>Update</button>
  <ReactCommandManager modules={modules} />
</div>

); }

ReactDOM.createRoot(document.getElementById('root')!).render( );

> 2. define a command
```jsx
import { defineCommand } from '@jswork/command-manager';

export default defineCommand({
  methods: {
    init(){
      console.log('init posts will execute at first time');
    },
    create() {
      console.log('create posts');
    },
    update({ title }) {
      console.log('update post', title);
    },
  },
});

3. execute a command

<button onClick={() => nx.$exec('posts.create')}>Create</button>
1.0.5

11 months ago

1.0.4

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago