From 1d5c76b6c030ba4693a5d433d15ebbdea788c4b8 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 24 Aug 2018 15:05:43 +0200 Subject: [PATCH 1/3] Add setApi and setProvider methods --- packages/light.js/package.json | 2 +- packages/light.js/src/api.ts | 14 ++++++++++++++ packages/light.js/src/index.ts | 6 +++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/light.js/package.json b/packages/light.js/package.json index cd489612..db45993c 100644 --- a/packages/light.js/package.json +++ b/packages/light.js/package.json @@ -1,7 +1,7 @@ { "name": "@parity/light.js", "description": "A high-level reactive JS library optimized for light clients", - "version": "1.0.2", + "version": "1.0.3", "author": "Parity Team ", "license": "MIT", "repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js", diff --git a/packages/light.js/src/api.ts b/packages/light.js/src/api.ts index b90f9b63..7bbbca77 100644 --- a/packages/light.js/src/api.ts +++ b/packages/light.js/src/api.ts @@ -24,6 +24,20 @@ export class NullProvider extends EventEmitter { } } +/** + * Sets a new Api object. + * + * @param newApi - An Api object. + */ +export const setApi = (newApi: any) => { + api = newApi; + if (!api.isPubSub) { + console.warn( + `Current provider does not support pubsub. @parity/light.js will poll every second to listen to changes.` + ); + } +}; + /** * Sets a new Ethereum provider object. * diff --git a/packages/light.js/src/index.ts b/packages/light.js/src/index.ts index b0fb7597..b129cd41 100644 --- a/packages/light.js/src/index.ts +++ b/packages/light.js/src/index.ts @@ -3,7 +3,7 @@ // // SPDX-License-Identifier: MIT -import { setProvider } from './api'; +import { setApi, setProvider } from './api'; import * as frequency from './frequency'; import './overview'; @@ -12,5 +12,5 @@ export * from './utils/isLoading'; export * from './types'; export { withoutLoading } from './utils/operators/withoutLoading'; -export { frequency, setProvider }; -export default { setProvider }; +export { frequency }; +export default { setApi, setProvider }; From ef2cb3d9bd8961bdd51d30db6ede4226096c6f00 Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 24 Aug 2018 15:05:48 +0200 Subject: [PATCH 2/3] Update docs --- packages/light.js/docs/api/README.md | 107 ++---------------- .../interfaces/_types_.frequencyobservable.md | 2 +- .../docs/api/interfaces/_types_.metadata.md | 14 +-- .../api/interfaces/_types_.rpcobservable.md | 10 +- .../docs/api/interfaces/_types_.txstatus.md | 14 +-- packages/light.js/docs/api/modules/_api_.md | 27 ++++- .../docs/api/modules/_frequency_accounts_.md | 4 +- .../docs/api/modules/_frequency_blocks_.md | 6 +- .../docs/api/modules/_frequency_health_.md | 2 +- .../docs/api/modules/_frequency_other_.md | 2 +- .../docs/api/modules/_frequency_time_.md | 6 +- .../docs/api/modules/_rpc_eth_eth_.md | 12 +- .../docs/api/modules/_rpc_net_net_.md | 2 +- .../api/modules/_rpc_other_makecontract_.md | 2 +- .../docs/api/modules/_rpc_other_post_.md | 2 +- .../docs/api/modules/_rpc_parity_parity_.md | 4 +- packages/light.js/docs/api/modules/_types_.md | 8 +- .../docs/api/modules/_utils_isloading_.md | 6 +- .../_utils_operators_withoutloading_.md | 2 +- 19 files changed, 81 insertions(+), 151 deletions(-) diff --git a/packages/light.js/docs/api/README.md b/packages/light.js/docs/api/README.md index 4332c7f7..2e932c82 100644 --- a/packages/light.js/docs/api/README.md +++ b/packages/light.js/docs/api/README.md @@ -4,7 +4,7 @@ A high-level reactive JS library optimized for light clients. -[![Build Status](https://travis-ci.org/paritytech/js-libs.svg?branch=master)](https://travis-ci.org/paritytech/js-libs) [![npm (scoped)](https://img.shields.io/npm/v/@parity/light.js.svg)](https://www.npmjs.com/package/@parity/light.js) [![dependencies Status](https://david-dm.org/paritytech/js-libs/status.svg?path=packages/light.js)](https://david-dm.org/paritytech/js-libs?path=packages/light.js) +[![Build Status](https://travis-ci.org/paritytech/js-libs.svg?branch=master)](https://travis-ci.org/paritytech/js-libs) [![npm (scoped)](https://img.shields.io/npm/v/@parity/light.js.svg)](https://www.npmjs.com/package/@parity/light.js) [![npm](https://img.shields.io/npm/dw/@parity/light.js.svg)](https://www.npmjs.com/package/@parity/light.js) [![dependencies Status](https://david-dm.org/paritytech/js-libs/status.svg?path=packages/light.js)](https://david-dm.org/paritytech/js-libs?path=packages/light.js) Getting Started --------------- @@ -19,7 +19,9 @@ Usage Reactively observe JSONRPC methods: ```javascript -import { defaultAccount$ } from '@parity/light.js'; +import light, { defaultAccount$ } from '@parity/light.js'; + +light.setProvider(/* put your ethereum provider here */); defaultAccount$().subscribe(publicAddress => console.log(publicAddress)); // Outputs your public address 0x... @@ -66,7 +68,7 @@ defaultAccount$() .subscribe(console.log); // Will log the result, and everytime the result changes ``` -All available methods are documented [in the docs](https://parity-js.github.io/light.js/). +All available methods are documented [in the docs](TODO). Usage with React ---------------- @@ -74,15 +76,15 @@ Usage with React The libray provides a higher-order component to use these Observables easily with React apps. ```javascript -import light from '???'; // ??? to be decided -import { syncing$ } from '@parity/light.js'; +import light from 'parity/ligth.js-react'; +import { syncStatus$ } from '@parity/light.js'; @light({ - syncingVariable: syncing$ + mySyncVariable: syncStatus$ }) class MyClass extends React.Component { render() { - return
{JSON.stringify(this.props.syncingVariable)}
; + return
{JSON.stringify(this.props.mySyncVariable)}
; } } ``` @@ -154,99 +156,8 @@ The keys are the Observables you are using in your dapp, each containing an obje This output can of course be different on different pages of your dapp, if they use different Observables. -Notes about Implementation --------------------------- - -### Observables are cold - -The underlying JSONRPC method is only called if there's at least one subscriber. - -```javascript -import { balanceOf$ } from '@parity/light.js'; - -const myObs$ = balanceOf$('0x123'); -// Observable created, but `eth_getBalance` not called yet -const subscription = myObs$.subscribe(console.log); -// `eth_getBalance` called for the 1st time - -// Some other code... - -subscription.unsubscribe(); -// `eth_getBalance` stops being called -``` - -### Observables are PublishReplay(1) - -Let's take `blockNumber()$` which fires blocks 7, 8 and 9, and has 3 subscribers that don't subscribe at the same time. - -We have the following marble diagram (`^` denotes when the subscriber subscribes). - -``` -blockNumber$(): -----7----------8------9-----| -subscriber1: -^---7----------8------9-----| -subscriber2: ------------^7--8------9-----| -subscriber3: --------------------------^9-| -``` - -Note: the default behavior for Observables is without PublishReplay, i.e. - -``` -blockNumber$(): -----7----------8------9-----| -subscriber1: -^---7----------8------9-----| -subscriber2: ------------^---8------9-----| -subscriber3: --------------------------^--| -``` - -But Observables in this library are PublishReplay(1). [Read more](https://blog.angularindepth.com/rxjs-how-to-use-refcount-73a0c6619a4e) about PublishReplay. - -### Observables are memoized - -```javascript -const obs1$ = balanceOf$('0x123'); -const obs2$ = balanceOf$('0x123'); -console.log(obs1$ === obs2$); // true - -const obs3$ = balanceOf$('0x456'); -console.log(obs1$ === obs3$); // false -``` - -### Underlying API calls are not unnessarily repeated - -```javascript -const obs1$ = balanceOf$('0x123'); -const obs2$ = balanceOf$('0x123'); - -obs1$.subscribe(console.log); -obs1$.subscribe(console.log); -obs2$.subscribe(console.log); -// Logs 3 times the balance -// But only one call to `eth_getBalance` has been made - -const obs3$ = balanceOf$('0x456'); -// Logs a new balance, another call to `eth_getBalance` is made -``` - -### Underlying PubSub subscriptions are dropped when there's no subscriber - -```javascript -import { blockNumber$ } from '@parity/light.js'; - -const myObs$ = blockNumber$(); -console.log(blockNumber$.frequency); // [onEveryBlock$] -// Note: onEveryBlock$ creates a pubsub on `eth_blockNumber` - -const subscription = myObs$.subscribe(console.log); -// Creates a pubsub subscription - -// Some other code... - -subscription.unsubscribe(); -// Drops the pubsub subscription -``` - TODO ---- -* Switch to TypeScript. * Have 100% test coverage. diff --git a/packages/light.js/docs/api/interfaces/_types_.frequencyobservable.md b/packages/light.js/docs/api/interfaces/_types_.frequencyobservable.md index 30cad509..5efca752 100644 --- a/packages/light.js/docs/api/interfaces/_types_.frequencyobservable.md +++ b/packages/light.js/docs/api/interfaces/_types_.frequencyobservable.md @@ -57,7 +57,7 @@ ___ **● metadata**: *`object`* -*Defined in [types.ts:38](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L38)* +*Defined in [types.ts:38](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L38)* #### Type declaration diff --git a/packages/light.js/docs/api/interfaces/_types_.metadata.md b/packages/light.js/docs/api/interfaces/_types_.metadata.md index 63279e4a..cb15884a 100644 --- a/packages/light.js/docs/api/interfaces/_types_.metadata.md +++ b/packages/light.js/docs/api/interfaces/_types_.metadata.md @@ -15,11 +15,11 @@ **● calledWithArgs**: *`object`* -*Defined in [types.ts:27](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L27)* +*Defined in [types.ts:27](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L27)* #### Type declaration -[key: `string`]: `any` +[key: `string`]: `ReplaySubject`<`Out`> ___ @@ -28,7 +28,7 @@ ___ **● calls**: *`string`[]* -*Defined in [types.ts:30](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L30)* +*Defined in [types.ts:30](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L30)* ___ @@ -37,7 +37,7 @@ ___ **● dependsOn**: *[RpcObservable](_types_.rpcobservable.md)<`any`, `Source`>* -*Defined in [types.ts:31](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L31)* +*Defined in [types.ts:31](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L31)* ___ @@ -46,7 +46,7 @@ ___ **● frequency**: *[FrequencyObservable](_types_.frequencyobservable.md)<`Source`>[]* -*Defined in [types.ts:32](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L32)* +*Defined in [types.ts:32](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L32)* ___ @@ -55,7 +55,7 @@ ___ **● name**: *`string`* -*Defined in [types.ts:33](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L33)* +*Defined in [types.ts:33](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L33)* ___ @@ -64,7 +64,7 @@ ___ **● pipes**: *`function`* -*Defined in [types.ts:34](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L34)* +*Defined in [types.ts:34](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L34)* #### Type declaration ▸(...args: *`any`[]*): `OperatorFunction`<`Source`, `Out`>[] diff --git a/packages/light.js/docs/api/interfaces/_types_.rpcobservable.md b/packages/light.js/docs/api/interfaces/_types_.rpcobservable.md index 1f11329b..2419dc14 100644 --- a/packages/light.js/docs/api/interfaces/_types_.rpcobservable.md +++ b/packages/light.js/docs/api/interfaces/_types_.rpcobservable.md @@ -10,7 +10,7 @@ # Callable ▸ **__call**(...args: *`any`[]*): `Observable`<`Out`> -*Defined in [types.ts:41](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L41)* +*Defined in [types.ts:41](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L41)* **Parameters:** @@ -28,7 +28,7 @@ **● metadata**: *[Metadata](_types_.metadata.md)<`Source`, `Out`>* -*Defined in [types.ts:43](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L43)* +*Defined in [types.ts:43](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L43)* ___ @@ -38,15 +38,15 @@ ___ ## `` setFrequency -▸ **setFrequency**(frequency: *`Observable`<[ApiValue](../modules/_types_.md#apivalue)>[]*): `void` +▸ **setFrequency**(frequency: *[FrequencyObservable](_types_.frequencyobservable.md)<`Source`>[]*): `void` -*Defined in [types.ts:44](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L44)* +*Defined in [types.ts:44](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L44)* **Parameters:** | Param | Type | | ------ | ------ | -| frequency | `Observable`<[ApiValue](../modules/_types_.md#apivalue)>[] | +| frequency | [FrequencyObservable](_types_.frequencyobservable.md)<`Source`>[] | **Returns:** `void` diff --git a/packages/light.js/docs/api/interfaces/_types_.txstatus.md b/packages/light.js/docs/api/interfaces/_types_.txstatus.md index fa1331f1..7c02c3ee 100644 --- a/packages/light.js/docs/api/interfaces/_types_.txstatus.md +++ b/packages/light.js/docs/api/interfaces/_types_.txstatus.md @@ -12,7 +12,7 @@ **● confirmed**: *`any`* -*Defined in [types.ts:55](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L55)* +*Defined in [types.ts:55](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L55)* ___ @@ -21,7 +21,7 @@ ___ **● estimated**: *`BigNumber`* -*Defined in [types.ts:57](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L57)* +*Defined in [types.ts:57](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L57)* ___ @@ -30,7 +30,7 @@ ___ **● estimating**: *`boolean`* -*Defined in [types.ts:56](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L56)* +*Defined in [types.ts:56](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L56)* ___ @@ -39,7 +39,7 @@ ___ **● failed**: *`Error`* -*Defined in [types.ts:58](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L58)* +*Defined in [types.ts:58](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L58)* ___ @@ -48,7 +48,7 @@ ___ **● requested**: *`string`* -*Defined in [types.ts:59](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L59)* +*Defined in [types.ts:59](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L59)* ___ @@ -57,7 +57,7 @@ ___ **● schedule**: *`any`* -*Defined in [types.ts:60](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L60)* +*Defined in [types.ts:60](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L60)* ___ @@ -66,7 +66,7 @@ ___ **● signed**: *`string`* -*Defined in [types.ts:61](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L61)* +*Defined in [types.ts:61](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L61)* ___ diff --git a/packages/light.js/docs/api/modules/_api_.md b/packages/light.js/docs/api/modules/_api_.md index 767c92f9..50ffda35 100644 --- a/packages/light.js/docs/api/modules/_api_.md +++ b/packages/light.js/docs/api/modules/_api_.md @@ -8,7 +8,7 @@ ▸ **getApi**(): `any` -*Defined in [api.ts:48](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/api.ts#L48)* +*Defined in [api.ts:62](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/api.ts#L62)* We only ever use api() at call-time of functions; this allows the options (particularly the transport option) to be changed dynamically and the data structure to be reused. @@ -22,15 +22,34 @@ ___ ▸ **setApi**(newApi: *`any`*): `void` -*Defined in [api.ts:32](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/api.ts#L32)* +*Defined in [api.ts:32](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/api.ts#L32)* -Sets an Api object. +Sets a new Api object. **Parameters:** | Param | Type | Description | | ------ | ------ | ------ | -| newApi | `any` | The Api object. | +| newApi | `any` | An Api object. | + +**Returns:** `void` + +___ + + +## `` setProvider + +▸ **setProvider**(provider: *`any`*): `void` + +*Defined in [api.ts:46](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/api.ts#L46)* + +Sets a new Ethereum provider object. + +**Parameters:** + +| Param | Type | Description | +| ------ | ------ | ------ | +| provider | `any` | An Ethereum provider object. | **Returns:** `void` diff --git a/packages/light.js/docs/api/modules/_frequency_accounts_.md b/packages/light.js/docs/api/modules/_frequency_accounts_.md index 16a36c57..df5a7389 100644 --- a/packages/light.js/docs/api/modules/_frequency_accounts_.md +++ b/packages/light.js/docs/api/modules/_frequency_accounts_.md @@ -11,7 +11,7 @@ api ) -*Defined in [frequency/accounts.ts:13](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/accounts.ts#L13)* +*Defined in [frequency/accounts.ts:13](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/accounts.ts#L13)* Observable that emits each time the default account changes @@ -25,7 +25,7 @@ ___ api ) -*Defined in [frequency/accounts.ts:22](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/accounts.ts#L22)* +*Defined in [frequency/accounts.ts:22](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/accounts.ts#L22)* Observable that emits each time the default account changes diff --git a/packages/light.js/docs/api/modules/_frequency_blocks_.md b/packages/light.js/docs/api/modules/_frequency_blocks_.md index f44a7980..a08fc604 100644 --- a/packages/light.js/docs/api/modules/_frequency_blocks_.md +++ b/packages/light.js/docs/api/modules/_frequency_blocks_.md @@ -10,7 +10,7 @@ filter(n => +n % 2 === 0) // Around ~30s on mainnet // TODO Use isEqualTo and mod from bignumber.js ) as FrequencyObservable -*Defined in [frequency/blocks.ts:25](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/blocks.ts#L25)* +*Defined in [frequency/blocks.ts:25](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/blocks.ts#L25)* Observable that emits on every 2nd block. @@ -23,7 +23,7 @@ ___ filter(n => +n % 4 === 0) // Around ~1min on mainnet // TODO Use isEqualTo and mod from bignumber.js ) as FrequencyObservable -*Defined in [frequency/blocks.ts:33](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/blocks.ts#L33)* +*Defined in [frequency/blocks.ts:33](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/blocks.ts#L33)* Observable that emits on every 4th block. @@ -37,7 +37,7 @@ ___ api ) -*Defined in [frequency/blocks.ts:16](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/blocks.ts#L16)* +*Defined in [frequency/blocks.ts:16](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/blocks.ts#L16)* Observable that emits on every new block. diff --git a/packages/light.js/docs/api/modules/_frequency_health_.md b/packages/light.js/docs/api/modules/_frequency_health_.md index 34094e4f..dce38a76 100644 --- a/packages/light.js/docs/api/modules/_frequency_health_.md +++ b/packages/light.js/docs/api/modules/_frequency_health_.md @@ -11,7 +11,7 @@ api ) -*Defined in [frequency/health.ts:22](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/health.ts#L22)* +*Defined in [frequency/health.ts:22](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/health.ts#L22)* Observable that emits when syncing status changes. diff --git a/packages/light.js/docs/api/modules/_frequency_other_.md b/packages/light.js/docs/api/modules/_frequency_other_.md index bfd51cc7..9c682a3a 100644 --- a/packages/light.js/docs/api/modules/_frequency_other_.md +++ b/packages/light.js/docs/api/modules/_frequency_other_.md @@ -8,7 +8,7 @@ **● onStartup$**: *[FrequencyObservable](../interfaces/_types_.frequencyobservable.md)<`number`>* = of(0) as FrequencyObservable -*Defined in [frequency/other.ts:13](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/other.ts#L13)* +*Defined in [frequency/other.ts:13](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/other.ts#L13)* Observable that emits only once. diff --git a/packages/light.js/docs/api/modules/_frequency_time_.md b/packages/light.js/docs/api/modules/_frequency_time_.md index 66142575..45e81b4a 100644 --- a/packages/light.js/docs/api/modules/_frequency_time_.md +++ b/packages/light.js/docs/api/modules/_frequency_time_.md @@ -8,7 +8,7 @@ **● onEvery2Seconds$**: *[FrequencyObservable](../interfaces/_types_.frequencyobservable.md)<`number`>* = timer(0, 2000) as FrequencyObservable -*Defined in [frequency/time.ts:19](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/time.ts#L19)* +*Defined in [frequency/time.ts:19](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/time.ts#L19)* Observable that emits on every other second. @@ -19,7 +19,7 @@ ___ **● onEvery5Seconds$**: *[FrequencyObservable](../interfaces/_types_.frequencyobservable.md)<`number`>* = timer(0, 5000) as FrequencyObservable -*Defined in [frequency/time.ts:25](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/time.ts#L25)* +*Defined in [frequency/time.ts:25](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/time.ts#L25)* Observable that emits every five seconds. @@ -30,7 +30,7 @@ ___ **● onEverySecond$**: *[FrequencyObservable](../interfaces/_types_.frequencyobservable.md)<`number`>* = timer(0, 1000) as FrequencyObservable -*Defined in [frequency/time.ts:13](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/frequency/time.ts#L13)* +*Defined in [frequency/time.ts:13](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/frequency/time.ts#L13)* Observable that emits on every second. diff --git a/packages/light.js/docs/api/modules/_rpc_eth_eth_.md b/packages/light.js/docs/api/modules/_rpc_eth_eth_.md index dea8febc..e2a46966 100644 --- a/packages/light.js/docs/api/modules/_rpc_eth_eth_.md +++ b/packages/light.js/docs/api/modules/_rpc_eth_eth_.md @@ -11,7 +11,7 @@ name: 'accounts$' }) -*Defined in [rpc/eth/eth.ts:30](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/eth/eth.ts#L30)* +*Defined in [rpc/eth/eth.ts:30](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/eth/eth.ts#L30)* Observable which contains the array of all addresses managed by the light client. @@ -32,7 +32,7 @@ ___ ] }) -*Defined in [rpc/eth/eth.ts:41](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/eth/eth.ts#L41)* +*Defined in [rpc/eth/eth.ts:41](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/eth/eth.ts#L41)* Get the balance of a given account. Calls `eth_getBalance`. *__param__*: The account address to query the balance. @@ -49,7 +49,7 @@ ___ name: 'blockNumber$' }) -*Defined in [rpc/eth/eth.ts:67](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/eth/eth.ts#L67)* +*Defined in [rpc/eth/eth.ts:67](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/eth/eth.ts#L67)* Get the current block number. *__returns__*: * An Observable containing the block height. @@ -65,7 +65,7 @@ ___ pipes: () => [map(accounts => accounts[0])] }) -*Defined in [rpc/eth/eth.ts:56](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/eth/eth.ts#L56)* +*Defined in [rpc/eth/eth.ts:56](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/eth/eth.ts#L56)* Get the default account managed by the light client. *__returns__*: * An Observable containing the public address of the default account. @@ -89,7 +89,7 @@ ___ ] }) -*Defined in [rpc/eth/eth.ts:75](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/eth/eth.ts#L75)* +*Defined in [rpc/eth/eth.ts:75](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/eth/eth.ts#L75)* Shorthand for fetching the current account's balance. @@ -103,7 +103,7 @@ ___ name: 'syncStatus$' }) -*Defined in [rpc/eth/eth.ts:94](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/eth/eth.ts#L94)* +*Defined in [rpc/eth/eth.ts:94](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/eth/eth.ts#L94)* Get the syncStatus state. *__returns__*: * An Observable containing the syncing state object, or false. diff --git a/packages/light.js/docs/api/modules/_rpc_net_net_.md b/packages/light.js/docs/api/modules/_rpc_net_net_.md index 09f27de2..d7580506 100644 --- a/packages/light.js/docs/api/modules/_rpc_net_net_.md +++ b/packages/light.js/docs/api/modules/_rpc_net_net_.md @@ -13,7 +13,7 @@ pipes: () => [switchMapPromise(() => api().net.peerCount())] }) -*Defined in [rpc/net/net.ts:20](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/net/net.ts#L20)* +*Defined in [rpc/net/net.ts:20](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/net/net.ts#L20)* Get the amount of peers. diff --git a/packages/light.js/docs/api/modules/_rpc_other_makecontract_.md b/packages/light.js/docs/api/modules/_rpc_other_makecontract_.md index 9b415e4f..db7f162a 100644 --- a/packages/light.js/docs/api/modules/_rpc_other_makecontract_.md +++ b/packages/light.js/docs/api/modules/_rpc_other_makecontract_.md @@ -64,7 +64,7 @@ { length: 1 } // Only memoize by address ) -*Defined in [rpc/other/makeContract.ts:49](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/other/makeContract.ts#L49)* +*Defined in [rpc/other/makeContract.ts:48](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/other/makeContract.ts#L48)* Create a contract. *__param__*: The contract address. diff --git a/packages/light.js/docs/api/modules/_rpc_other_post_.md b/packages/light.js/docs/api/modules/_rpc_other_post_.md index a672e96a..589189e6 100644 --- a/packages/light.js/docs/api/modules/_rpc_other_post_.md +++ b/packages/light.js/docs/api/modules/_rpc_other_post_.md @@ -8,7 +8,7 @@ ▸ **post$**(tx: *[Tx](_types_.md#tx)*, options?: *`object`*): `any` -*Defined in [rpc/other/post.ts:22](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/other/post.ts#L22)* +*Defined in [rpc/other/post.ts:22](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/other/post.ts#L22)* Post a transaction to the network. diff --git a/packages/light.js/docs/api/modules/_rpc_parity_parity_.md b/packages/light.js/docs/api/modules/_rpc_parity_parity_.md index bff2e335..4ab35a93 100644 --- a/packages/light.js/docs/api/modules/_rpc_parity_parity_.md +++ b/packages/light.js/docs/api/modules/_rpc_parity_parity_.md @@ -11,7 +11,7 @@ name: 'accountsInfo$' }) -*Defined in [rpc/parity/parity.ts:18](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/parity/parity.ts#L18)* +*Defined in [rpc/parity/parity.ts:18](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/parity/parity.ts#L18)* Get accounts info. Calls `parity_accountsInfo`. *__returns__*: * An Observable containing all info that can be accessed by user concerning accounts. @@ -28,7 +28,7 @@ ___ pipes: () => [switchMapPromise(() => api().parity.netChain())] }) -*Defined in [rpc/parity/parity.ts:29](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/rpc/parity/parity.ts#L29)* +*Defined in [rpc/parity/parity.ts:29](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/rpc/parity/parity.ts#L29)* Get the name of the current chain. Calls `parity_netChain`. *__returns__*: * An Observable containing the name of the current chain. diff --git a/packages/light.js/docs/api/modules/_types_.md b/packages/light.js/docs/api/modules/_types_.md index dcb7d0fa..571d58ec 100644 --- a/packages/light.js/docs/api/modules/_types_.md +++ b/packages/light.js/docs/api/modules/_types_.md @@ -8,7 +8,7 @@ **ΤAccountsInfo**: *`object`* -*Defined in [types.ts:16](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L16)* +*Defined in [types.ts:16](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L16)* #### Type declaration @@ -19,7 +19,7 @@ ___ **ΤAddress**: *`string`* -*Defined in [types.ts:21](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L21)* +*Defined in [types.ts:21](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L21)* ___ @@ -28,7 +28,7 @@ ___ **ΤApiValue**: *`any`* -*Defined in [types.ts:24](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L24)* +*Defined in [types.ts:24](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L24)* ___ @@ -37,7 +37,7 @@ ___ **ΤTx**: *`object`* -*Defined in [types.ts:48](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/types.ts#L48)* +*Defined in [types.ts:48](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/types.ts#L48)* #### Type declaration diff --git a/packages/light.js/docs/api/modules/_utils_isloading_.md b/packages/light.js/docs/api/modules/_utils_isloading_.md index adad5e0c..e4d4c949 100644 --- a/packages/light.js/docs/api/modules/_utils_isloading_.md +++ b/packages/light.js/docs/api/modules/_utils_isloading_.md @@ -8,7 +8,7 @@ **● RPC_LOADING**: *`unique symbol`* = Symbol('Fetching RPC...') -*Defined in [utils/isLoading.ts:6](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/utils/isLoading.ts#L6)* +*Defined in [utils/isLoading.ts:6](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/utils/isLoading.ts#L6)* ___ @@ -20,7 +20,7 @@ ___ ▸ **isLoading**(value: *`any`*): `boolean` -*Defined in [utils/isLoading.ts:14](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/utils/isLoading.ts#L14)* +*Defined in [utils/isLoading.ts:14](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/utils/isLoading.ts#L14)* Check if a rpc$ value is loading. @@ -40,7 +40,7 @@ ___ ▸ **isNullOrLoading**(value: *`any`*): `boolean` -*Defined in [utils/isLoading.ts:22](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/utils/isLoading.ts#L22)* +*Defined in [utils/isLoading.ts:22](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/utils/isLoading.ts#L22)* Check if a rpc$ value is `null,`undefined` or loading. diff --git a/packages/light.js/docs/api/modules/_utils_operators_withoutloading_.md b/packages/light.js/docs/api/modules/_utils_operators_withoutloading_.md index 53e9a7fd..4cb4853b 100644 --- a/packages/light.js/docs/api/modules/_utils_operators_withoutloading_.md +++ b/packages/light.js/docs/api/modules/_utils_operators_withoutloading_.md @@ -8,7 +8,7 @@ ▸ **withoutLoading**(): `(Anonymous function)` -*Defined in [utils/operators/withoutLoading.ts:14](https://github.com/paritytech/js-libs/blob/a8a861f/packages/light.js/src/utils/operators/withoutLoading.ts#L14)* +*Defined in [utils/operators/withoutLoading.ts:14](https://github.com/paritytech/js-libs/blob/c75381e/packages/light.js/src/utils/operators/withoutLoading.ts#L14)* Filter out the loading states in our observable. From d02a6c86fecabe7e13b58137e0ed9ac4eac6650f Mon Sep 17 00:00:00 2001 From: Amaury Martiny Date: Fri, 24 Aug 2018 15:07:34 +0200 Subject: [PATCH 3/3] Fix tests --- packages/light.js/src/api.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/light.js/src/api.spec.ts b/packages/light.js/src/api.spec.ts index ff05ad01..0a540d5d 100644 --- a/packages/light.js/src/api.spec.ts +++ b/packages/light.js/src/api.spec.ts @@ -3,7 +3,7 @@ // // SPDX-License-Identifier: MIT -import { getApi, NullProvider, setProvider } from './api'; +import { getApi, NullProvider, setApi } from './api'; import { resolveApi } from './utils/testHelpers/mockApi'; it('should return the Null provider', () => { @@ -12,12 +12,12 @@ it('should return the Null provider', () => { it('should correctly set a new Api', () => { const mockApi = resolveApi(undefined, false); // Pubsub - setProvider(mockApi); + setApi(mockApi); expect(getApi()).toBe(mockApi); }); it('should correctly set a new Api', () => { const mockApi = resolveApi(undefined, false); // Not pubsub - setProvider(mockApi); + setApi(mockApi); expect(getApi()).toBe(mockApi); });