0.0.3 • Published 4 years ago

@capsulajs/capsulahub-service-selector v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

Selector service

The purpose of this service is to provide a utility tool that allows user to select a specific data inside a collection of data.

Install

NPM

To install the package from NPM registry you should run

yarn add @capsulajs/capsulahub-service-selector

or

npm install @capsulajs/capsulahub-service-selector

CDN

You can get the default export from the link

https://capsulajs.s3.amazonaws.com/develop/service-selector/index.js

Exports

Default

Bootstrap function of the extension.

Named (API)

The public API of the extension.

Usage

This service takes two typed elements (Item and Key).

import { Selector } from '@capsulajs/capsulahub-service-selector';

interface Item {
  name: string;
  age: number;
  role: string;
}

interface Key {
  name: string;
}

const data = [
  { name: 'Pim', age: 22, role: 'first' },
  { name: 'Pam', age: 42, role: 'second' },
  { name: 'Pom', age: 32, role: 'third' },
];
// Init selector with typed elements
const selector = new Selector<Item, Key>();
// Fill the selector with data
selector.setItems({ items: data })
  .then(() => console.log(`setItems completed`));
// Subscribe to selector's data
selector.items$({}).subscribe(console.log);
// Output 
// [ { name: 'Pim', age: 22, role: 'first' },
//   { name: 'Pam', age: 42, role: 'second' },
//   { name: 'Pom', age: 32, role: 'third' } ]

// Select an Item
selector.selectItem({ key: { name: 'Pim' }})
  .then(() => console.log(`Item selected`));
// Subscribe to selector selected item
selector.selectedItem$({}).subscribe(console.log);
// Output
// { name: 'Pim', age: 22, role: 'first' }

API

CDN

The documentation about public API.

Local

Run

yarn doc

And open doc/index.html in browser.

Test

npm run test or yarn test

Licence

CapsulaHub and related services are released under MIT Licence.

Back to the Main Page

0.0.2-next.35

4 years ago

0.0.3

4 years ago

0.0.2-next.32

4 years ago

0.0.2-next.19

5 years ago

0.0.2-next.14

5 years ago

0.0.2-next.11

5 years ago

0.0.2-next.9

5 years ago

0.0.2-next.7

5 years ago

0.0.2-next.6

5 years ago

0.0.2-next.2

5 years ago

0.0.2-next.1

5 years ago

0.0.2-alpha.5

5 years ago

0.0.2-alpha.4

5 years ago

0.0.2-alpha.3

5 years ago

0.0.2-alpha.2

5 years ago

0.0.2-alpha.1

5 years ago

0.0.2-alpha.0

5 years ago

0.0.1

5 years ago