UNPKG

2.15 kBTypeScriptView Raw
1/**
2@license
3Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
4This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7Code distributed by Google as part of the polymer project is also
8subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9*/
10import { Store, Unsubscribe } from 'redux';
11declare type Constructor<T> = new (...args: any[]) => T;
12/**
13 By using this `CustomElement` interface instead of `HTMLElement`, we avoid
14 having the generated typings include most DOM API already provided by
15 TypeScript. This is particularly useful since different versions of
16 TypeScript may have different DOM API typings (e.g. TS 3.0.3 and TS 3.1.1).
17 The required `isConnected` property is included to avoid the following
18 TypeScript error:
19
20 Type 'HTMLElement' has no properties in common with type 'CustomElement'.
21*/
22interface CustomElement {
23 connectedCallback?(): void;
24 disconnectedCallback?(): void;
25 readonly isConnected: boolean;
26}
27/**
28 This is a JavaScript mixin that you can use to connect a Custom Element base
29 class to a Redux store. The `stateChanged(state)` method will be called when
30 the state is updated.
31
32 Example:
33
34 import { connect } from 'pwa-helpers/connect-mixin.js';
35
36 class MyElement extends connect(store)(HTMLElement) {
37 stateChanged(state) {
38 this.textContent = state.data.count.toString();
39 }
40 }
41*/
42export declare const connect: <S>(store: Store<S, import("redux").AnyAction>) => <T extends Constructor<CustomElement>>(baseElement: T) => {
43 new (...args: any[]): {
44 _storeUnsubscribe: Unsubscribe;
45 connectedCallback(): void;
46 disconnectedCallback(): void;
47 /**
48 * The `stateChanged(state)` method will be called when the state is updated.
49 */
50 stateChanged(_state: S): void;
51 readonly isConnected: boolean;
52 };
53} & T;
54export {};