Skip to content

Commit

Permalink
stores
Browse files Browse the repository at this point in the history
  • Loading branch information
ampatspell committed Nov 22, 2020
1 parent 3481fe9 commit 7beaad7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
25 changes: 24 additions & 1 deletion docs/api/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ pos: 6

# Functions

``` javascript
let functions = store.functions;
let response = await functions.call('hello', { ok: true });
response // → { data: { … } }
```

## async call(name, props) `→ object`

Calls Firebase callable function in default region.

Alias for `functions.region().call(...args)`

## region()

Returns default region.

See [Store](api/store) `options.functions` on how to setup custom default region.

## region(identifier)

## call(name, props)
Returns custom region.

``` javascript
let region = functions.region('europe-west1');
await region.call('hello', { ok: true });
```
19 changes: 17 additions & 2 deletions docs/api/functions/region.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ pos: 0

# Region

## identifier
## identifier `→ string`

## call(name, props)
Region identifier

``` javascript
let region = store.functions.region();
region.identifier // → 'us-central1'
```

## async call(name, props) `→ object`

Calls Firebase callable function.

``` javascript
let region = store.functions.region();
let result = await region.call('hello', { ok: true });
result // → { data: { … } }
```
48 changes: 43 additions & 5 deletions docs/api/stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,50 @@ pos: 7

# Stores

## stats
Stores manages any [Store](api/store) instances used in the app.

## models
Singleton, accessible using `getStores()` helper

## createStore(identifier, factory)
``` javascript
import { getStores } from 'zuglet/utils';
let stores = getStores(this);
```

## store(identifier, opts)
## stats `→ Stats`

## settle()
Returns singleton [Stats](api/stores/stats) instance.

## models `→ Models`

Returns singleton [Models](api/models) instance.

## createStore(identifier, factory) `→ Store`

Creates a new store.

``` javascript
import BaseStore from 'zuglet/store';

class Store extends BaseStore {
}

let store = getStores(this).createStore('store', Store);
```

## store(identifier, { optional })

Returns existing store.

* `optional` → boolean, defaults to false

``` javascript
let missing = getStores(this).store('missing', { optional: true });
missing // → undefined

let existing = getStores(this).store('existing');
existing // → Store
```

## async settle() → undefined

Alias for `stores.stats.settle()`

0 comments on commit 7beaad7

Please sign in to comment.