@gechiui/data-controls

2.2.8 • Public • Published

Data Controls

The data controls module is a module intended to simplify implementation of common controls used with the @gechiui/data package.

Note: It is assumed that the registry being used has the controls plugin enabled on it (see more details on controls here)

Installation

Install the module

npm install @gechiui/data-controls --save

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for such language features and APIs, you should include the polyfill shipped in @gechiui/babel-preset-default in your code.

The following controls are available on the object returned by the module:

API

apiFetch

Dispatches a control action for triggering an api fetch call.

Usage

import { apiFetch } from '@gechiui/data-controls';

// Action generator using apiFetch
export function* myAction() {
	const path = '/v2/my-api/items';
	const items = yield apiFetch( { path } );
	// do something with the items.
}

Parameters

  • request Object: Arguments for the fetch request.

Returns

  • Object: The control descriptor.

controls

The default export is what you use to register the controls with your custom store.

Usage

// GeChiUI dependencies
import { controls } from '@gechiui/data-controls';
import { registerStore } from '@gechiui/data';

// Internal dependencies
import reducer from './reducer';
import * as selectors from './selectors';
import * as actions from './actions';
import * as resolvers from './resolvers';

registerStore( 'my-custom-store', {
	reducer,
	controls,
	actions,
	selectors,
	resolvers,
} );

Returns

  • Object: An object for registering the default controls with the store.

dispatch

Control for dispatching an action in a registered data store. Alias for the dispatch control in the @gechiui/data package.

Parameters

  • args Array: Arguments passed without change to the @gechiui/data control.

select

Control for resolving a selector in a registered data store. Alias for the resolveSelect built-in control in the @gechiui/data package.

Parameters

  • args Array: Arguments passed without change to the @gechiui/data control.

syncSelect

Control for calling a selector in a registered data store. Alias for the select built-in control in the @gechiui/data package.

Parameters

  • args Array: Arguments passed without change to the @gechiui/data control.

Package Sidebar

Install

npm i @gechiui/data-controls

Weekly Downloads

1

Version

2.2.8

License

GPL-2.0-or-later

Unpacked Size

64.4 kB

Total Files

10

Last publish

Collaborators

  • gechiui