Skip to content

Commit

Permalink
sync features and bugfixs from 78da4bf (#1645)
Browse files Browse the repository at this point in the history
* sync features and bugfix from 78da4bf

* fix build issue
  • Loading branch information
embbnux authored Nov 4, 2020
1 parent a46e765 commit 81216ee
Show file tree
Hide file tree
Showing 1,166 changed files with 111,016 additions and 6,213 deletions.
2 changes: 1 addition & 1 deletion .sync
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a38a9cf4a805ccf70198c53d8f3b0fa4a5831aea
78da4bf412b439d382c6182f5bbd62b8f09324f9
32 changes: 16 additions & 16 deletions packages/babel-settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
},
"scripts": {},
"dependencies": {
"@babel/core": "^7.9.6",
"@babel/node": "^7.8.7",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-proposal-decorators": "^7.8.3",
"@babel/plugin-proposal-export-default-from": "^7.8.3",
"@babel/plugin-proposal-export-namespace-from": "^7.8.3",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
"@babel/plugin-proposal-object-rest-spread": "^7.9.6",
"@babel/plugin-proposal-optional-chaining": "^7.9.0",
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0",
"@babel/register": "^7.9.0",
"@babel/core": "^7.11.4",
"@babel/node": "^7.10.5",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-proposal-decorators": "^7.10.5",
"@babel/plugin-proposal-export-default-from": "^7.10.4",
"@babel/plugin-proposal-export-namespace-from": "^7.10.4",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.4",
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
"@babel/plugin-proposal-optional-chaining": "^7.11.0",
"@babel/preset-env": "^7.11.0",
"@babel/preset-react": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@babel/register": "^7.10.5",
"core-js": "^2.6.11",
"typescript": "^3.9.2"
"typescript": "^4.0.2"
},
"peerDependencies": {
"@babel/polyfill": "^7.6.0",
"babel-jest": "^24.8.0"
"@babel/polyfill": "^7.10.4",
"babel-jest": "^26.3.0"
},
"ci": {
"ringcentral-js-widgets": "**"
Expand Down
88 changes: 81 additions & 7 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,57 @@
# @ringcentral-integration/core

The foundation package for RingCentral Integration products.

## Usage

```sh
yarn add @ringcentral-integration/core
```

## APIs

- [RcModuleV2](#RcModule-APIs)
- onStateChange()
- onInit()
- onInitOnce()
- onReset()
- [RcUIModuleV2](#RcUIModule-APIs)
- [@state](#state-API)
- [@action](#action-API)
- [@storage](#Storage-and-GlobalStorage-APIs)
- [@globalStorage](#Storage-and-GlobalStorage-APIs)
- [@computed()](#computed-API)
- [@proxyState()](#proxyState-API)
- [@track()](#Tracking-APIs)
- [watch](#State-Subscription-APIs)

### RcModule APIs

* `@ringcentral-integration/core` provides `RcModuleV2` base module, decorators `state`, `action`, `computed`, `storage` and `globalStorage`.
`@ringcentral-integration/core` provides `RcModuleV2` base module, decorators `state`, `action`, `computed`, `storage` and `globalStorage`, `proxyState`.

The decorator `storage` depends on `Storage` Module, And The decorator `globalStorage` depends on `GlobalStorage` Module.

> You should have access to all the dependency modules via `this._deps.fooBar`.
- onInit()

`onInit` life cycle for current initialization before all deps modules are all ready.

- onInitOnce()

`onInitOnce` once life cycle for current initialization before all deps modules are all ready.

- onInitSuccess()

`onInitSuccess` life cycle for current initialization after this module is ready.

The decorator `storage` depends on `Storage` Module, And The decorator `globalStorage` depends on `GlobalStorage` Module.
- onReset()

> If you use `@computed(callback)`, you should make sure that the return value of its callback function is an Array of dependency collections.
`onReset` life cycle for current reset before one of deps modules is not ready.

> You should have access to all the dependency modules via `this._deps.xx`.
- onStateChange()

`onStateChange` each Redux dispatch action will trigger it once.

For example:

Expand Down Expand Up @@ -53,7 +90,42 @@ class Auth extends RcModuleV2<Deps> {
}
```

> Note: `@action` does **NOT** support asynchronous methods.
#### state API

`@state` is used to decorate a module state, which is based on the Redux reducer.

#### action API

`@action` is used to decorate a method that changes the state of the module (Executing it will dispatch a Redux action), and it does **NOT** support asynchronous methods.

#### computed API

Use `@computed(callback)`, you should make sure that the return value of its callback function is an `Array` of dependency collections.

```ts
class Auth extends RcModuleV2<Deps> {
constructor(deps: Deps) {
super({
deps,
});
}

@state
connected = '';

@state
readable = false;

@computed<Auth>(({ connected, readable }) => [connected, readable])
get permissions() {
return { writeable: getWriteable(this.connected), readable: this.readable };
}
}
```

#### proxyState API

`@proxyState` is used for asynchronous state changes of the browser client, and its parameter must be an asynchronous function and cannot be used with `@storage`/`@globalStorage`.

### RcUIModule APIs

Expand Down Expand Up @@ -121,9 +193,11 @@ class Auth extends RcModuleV2<Deps> {
}
```

> Note: All module options based on RcModuleV2 have `{ spread: true }` disabled on the DI settings.
### Storage and GlobalStorage APIs

`Storage` or `GlobalStorage` should injection in module with `ringcentral-integration/lib/di` if you need.
`Storage` or `GlobalStorage` should be injected in module with `ringcentral-integration/lib/di`.

And You should pass parameters `enableCache`, `enableGlobalCache` and `storageKey` in `constructor` for `super` args.

Expand Down Expand Up @@ -197,7 +271,7 @@ class Call extends RcModuleV2<Deps> {
### State Subscription APIs
* `watch`
- `watch`
It is used to subscribe to some state or `@computed` to get the derived computed state, which returns a callback function that can be used to cancel the subscription.
Expand Down
13 changes: 13 additions & 0 deletions packages/core/lib/ObjectMap/ObjectMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ export class ObjectMap<
return instance[sDefinition].forEach((v, k) => fn(v, k, instance));
}

static filter<D extends Record<K, V>, K extends keyof D, V extends D[K]>(
fn: (value: V, key: K) => boolean,
instance: ObjectMap<D, K, V> & D,
) {
const obj = {} as Record<K, V>;
ObjectMap.forEach((v, k) => {
if (fn(v, k)) {
obj[k] = v;
}
}, instance);
return ObjectMap.fromObject(obj);
}

static prefixValues<
D extends Record<K, string>,
K extends keyof D,
Expand Down
Loading

0 comments on commit 81216ee

Please sign in to comment.