1.7.14 • Published 1 year ago

@bity/preact-conversion-components v1.7.14

Weekly downloads
14
License
MIT
Repository
-
Last release
1 year ago

@bity/preact-conversion-components

A collection of components that make conversions against the Bity API.

See src/ for all the components and to learn how they work.

They are provided as ES2015 modules, and have already been transpiled once from JSX to regular ES2015+.

You will probably want to use these in combination with @bity/preact-base-components, @bity/preact-exchange-client, and @bity/styles.

Installation

npm install                          \
	@bity/api                          \
  @bity/data-stores                  \
  @bity/preact-conversion-components \
  @bity/styles                       \
  preact                             \
  preact-redux

Usage by example

It's somewhat convoluted to use these components because they try to do everything for you once provided with the correct information. They will periodically poll when there are listeners, and won't when there aren't any - small conveniences like that.

import { h, render } from 'preact';
import { Provider } from 'preact-redux';
import { BityApiClient } from '@bity/api';
import { Order } from '@bity/api/models';
import * as currenciesDataStore from '@bity/data-stores/currencies';
import * as orderDataStore from '@bity/data-stores/order';
import { getStore, initializeStores } from '@bity/data-stores/store';
import { ExchangeRate } from '@bity/preact-conversion-components/exchange-rate

// Initialize the API
const bityApiClient = new BityApiClient({
	exchangeApiUrl,
	legacyV2ApiUrl,
	clientId // Request a clientId from Bity's support.
});

// Initialize the state container with an API client instance
initializeStores({ bityApiClient });

// Get the store to get its dispatcher
const store = dataStore.getStore();
const { dispatch } = store;

// Get currencies information
currenciesDataStore.addDataListener(dispatch);

// To make a single initial request for exchange data
orderDataStore.removeDataListener(dispatch);
dispatch({ type: orderDataStore.DATA_UPDATE, payload: new Order() });
orderDataStore.addDataListener(dispatch);

render(
  <Provider store={store}>
    <ExchangeRate />
  <Provider/>,
  document.getElementById('root')
);

Save the file and run your favorite bundler/transpiler combination, and then:

<head>
  <!-- First include the default styling for the components. -->
  <link rel="stylesheet" type="text/css" href="node_modules/@bity/styles/index.css"/>
</head>

<body>
  <!-- Define a mount point: -->
  <div id="root"></div>

  <!-- Then include the bundle use. -->
  <script src="bundle.js"></script>
</body>

You should see some updating exchange rate on the screen.

1.7.14

1 year ago

1.7.10

2 years ago

1.7.11

2 years ago

1.7.12

2 years ago

1.7.13

2 years ago

1.7.9

2 years ago

1.7.8

2 years ago

1.7.7

2 years ago

1.7.6

2 years ago

1.7.5

2 years ago

1.7.4

2 years ago

1.7.3

2 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago