4.4.0 • Published 7 years ago

mva v4.4.0

Weekly downloads
16
License
MIT
Repository
-
Last release
7 years ago

Usage

MVA uses a state to represent the model. Components are views that render the model. An action, mostly initiated by a view notifies every model that subscribed to it. The model then can trigger a state transition and inform the views.

An action is easy to create. Here we define some actions for our flow model in src/actions/flow.js:

import { Action } from 'mva';

export const SetDialog = new Action();
export const SetContext = new Action();

Next we can create the flow model in src/state/flow.js and subscribe to these actions:

import * as Actions from '../actions/flow';

export default ({ init, on }) => {
    init('dialog', {});

    on(Actions.SetDialog, ({ dialog }, state, update) => {
        state.dialog = dialog;
        update(state);
    });

    on(Actions.setContext, ({ context }, state, update) => {
        update({ dialog }); // update directly
    });

};

The handler just takes an object containing the new dialog / context to set on the state and triggers the notification via the update(state) function. The models in src/state should all be exported in one file, e.g. src/store.js:

import { Store } from 'mva';
import Flow from './flow';

export default Store([ Flow ]);

The Store function initializes the models and passes the object with the available methods. These are init, on, load and persist. While init and on only do transient changes, the load and persist functions have side effects that get / set the state in the localstorage.

Components do not need to subscribe directly to any models. The exported Store is passed to the root node of the application, commonly called App. From there on the state gets (partially) distributed to child nodes like usually in React. An entry point lets the App subscribe to the Store, which then in turn passes the state initially and on every state transition to the App.

The definition of the entry is always the same, here in src/entry.js:

import { Run } from 'mva';
import App from './components/app';
import Store from './state/store';

// May also import styles here
import './style/app.scss';

Run(Store, App);

A Component can trigger an action by simply calling it with an argument. Note that Actions only take one argument. However, it's easy to work with if you pass always an object with the required parameters. The model than can destruct the object in the function parameter definition. For example the use of SetContext in the src/components/app.js file:

import { React } from 'mva';
import { SetContext } from '../actions/flow';

export default state => {
    const context = state.context ? state.context : 'No Context';

    return <div className="app">
        {`Context enabled: ${context}`}
        <button onClick={() => SetContext({ context: 'Test' }) }>
            Set context to Test
        </button>
        <button onClick={() => SetContext({ context: null } )}>
            Clear context
        </button>
    </div>
};

Components

MVA also includes implementations of commonly used components:

  • Accordion
  • Canvas
  • Checkbox
  • Combobox
  • Context
  • DatePicker
  • Dialog
  • FileBrowser
  • Form
  • List
  • Slide List
  • Split Panel
  • Tabs

TODO

  • Describe Component interfaces
  • Describe Store usage with load, persist and id
  • Enhance and introduce utils
4.4.0

7 years ago

4.3.16

7 years ago

4.3.15

7 years ago

4.3.14

7 years ago

4.3.13

7 years ago

4.3.12

7 years ago

4.3.11

7 years ago

4.3.10

7 years ago

4.3.9

7 years ago

4.3.8

7 years ago

4.3.7

7 years ago

4.3.6

7 years ago

4.3.5

7 years ago

4.3.4

7 years ago

4.3.3

7 years ago

4.3.2

7 years ago

4.3.1

7 years ago

4.3.0

7 years ago

4.2.12

7 years ago

4.2.11

7 years ago

4.2.10

7 years ago

4.2.9

7 years ago

4.2.8

7 years ago

4.2.7

7 years ago

4.2.6

7 years ago

4.2.5

7 years ago

4.2.4

7 years ago

4.2.3

7 years ago

4.2.2

7 years ago

4.2.1

7 years ago

4.2.0

7 years ago

4.1.20

7 years ago

4.1.19

7 years ago

4.1.18

7 years ago

4.1.17

7 years ago

4.1.16

7 years ago

4.1.15

7 years ago

4.1.14

7 years ago

4.1.13

7 years ago

4.1.12

7 years ago

4.1.11

7 years ago

4.1.10

7 years ago

4.1.9

7 years ago

4.1.8

7 years ago

4.1.7

7 years ago

4.1.6

7 years ago

4.1.5

7 years ago

4.1.4

7 years ago

4.1.3

7 years ago

4.1.2

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.9

7 years ago

4.0.8

7 years ago

4.0.7

7 years ago

4.0.6

7 years ago

4.0.5

7 years ago

4.0.4

7 years ago

4.0.3

7 years ago

4.0.2

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.4.2

8 years ago

3.4.1

8 years ago

3.4.0

8 years ago

3.3.9

8 years ago

3.3.8

8 years ago

3.3.7

8 years ago

3.3.6

8 years ago

3.3.5

8 years ago

3.3.4

8 years ago

3.3.3

8 years ago

3.3.2

8 years ago

3.3.1

8 years ago

3.3.0

8 years ago

3.2.9

8 years ago

3.2.8

8 years ago

3.2.7

8 years ago

3.2.6

8 years ago

3.2.5

8 years ago

3.2.4

8 years ago

3.2.3

8 years ago

3.2.2

8 years ago

3.2.1

8 years ago

3.2.0

8 years ago

3.0.0

8 years ago

2.1.0

8 years ago