From ad74bf27c34cb0ef99cb335c4bf9f3c0e14f7131 Mon Sep 17 00:00:00 2001 From: Edward Silverton Date: Wed, 21 Aug 2019 11:46:54 +0100 Subject: [PATCH 1/3] added default export to store --- src/global/store.ts | 94 +++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/src/global/store.ts b/src/global/store.ts index 9f18e52..311ff40 100644 --- a/src/global/store.ts +++ b/src/global/store.ts @@ -4,55 +4,57 @@ import { Store } from './interfaces'; declare var Context: any; -Context.store = ((): Store => { - let _store: ReduxStore; - - const setStore = (store: ReduxStore) => { - _store = store; - }; - - const getState = () => { - return _store && _store.getState(); - }; - - const getStore = () => { - return _store; - }; - - const mapDispatchToProps = (component: any, props: any) => { - Object.keys(props).forEach(actionName => { - const action = props[actionName]; - Object.defineProperty(component, actionName, { - get: () => (...args: any[]) => _store.dispatch(action(...args)), - configurable: true, - enumerable: true, - }); - }); - }; - - const mapStateToProps = (component: any, mapState: (...args: any[]) => any) => { - // TODO: Don't listen for each component - const _mapStateToProps = (_component: any, _mapState: any) => { - const mergeProps = mapState(_store.getState()); - Object.keys(mergeProps).forEach(newPropName => { - const newPropValue = mergeProps[newPropName]; - component[newPropName] = newPropValue; - // TODO: can we define new props and still have change detection work? +export default () => { + Context.store = ((): Store => { + let _store: ReduxStore; + + const setStore = (store: ReduxStore) => { + _store = store; + }; + + const getState = () => { + return _store && _store.getState(); + }; + + const getStore = () => { + return _store; + }; + + const mapDispatchToProps = (component: any, props: any) => { + Object.keys(props).forEach(actionName => { + const action = props[actionName]; + Object.defineProperty(component, actionName, { + get: () => (...args: any[]) => _store.dispatch(action(...args)), + configurable: true, + enumerable: true, + }); }); }; - const unsubscribe = _store.subscribe(() => _mapStateToProps(component, mapState)); + const mapStateToProps = (component: any, mapState: (...args: any[]) => any) => { + // TODO: Don't listen for each component + const _mapStateToProps = (_component: any, _mapState: any) => { + const mergeProps = mapState(_store.getState()); + Object.keys(mergeProps).forEach(newPropName => { + const newPropValue = mergeProps[newPropName]; + component[newPropName] = newPropValue; + // TODO: can we define new props and still have change detection work? + }); + }; - _mapStateToProps(component, mapState); + const unsubscribe = _store.subscribe(() => _mapStateToProps(component, mapState)); - return unsubscribe; - }; + _mapStateToProps(component, mapState); - return { - getStore, - setStore, - getState, - mapDispatchToProps, - mapStateToProps, - }; -})(); + return unsubscribe; + }; + + return { + getStore, + setStore, + getState, + mapDispatchToProps, + mapStateToProps, + }; + })(); +}; From 5ac06488bed0ae925503f70a23711ebdf6219a8d Mon Sep 17 00:00:00 2001 From: Edward Silverton Date: Thu, 21 May 2020 11:19:55 +0100 Subject: [PATCH 2/3] updated to stencil/core v1.12.2 --- .gitignore | 5 ++-- package.json | 14 +++--------- src/components.d.ts | 49 ++++++++++++---------------------------- src/global/interfaces.ts | 4 ++-- 4 files changed, 22 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index ab9cbca..26966da 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ dist/ -www/build +www/ +loader/ *~ *.sw[mnpcod] @@ -11,8 +12,8 @@ log.txt *.sublime-project *.sublime-workspace +.stencil/ .idea/ -.vscode/ .sass-cache/ .versions/ node_modules/ diff --git a/package.json b/package.json index efd632e..bcbf6f5 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.1", "description": "Stencil Redux - A simple redux-connector for Stencil-built web components", "main": "dist/index.js", - "module": "dist/esm/es5/index.js", + "module": "dist/index.mjs", "types": "dist/types/index.d.ts", "collection": "dist/collection/collection-manifest.json", "files": [ @@ -27,16 +27,8 @@ "url": "git+https://github.com/ionic-team/stencil-redux.git" }, "devDependencies": { - "@stencil/core": "^0.18.0", - "@types/jest": "^24.0.5", - "@types/redux": "^3.6.0", - "husky": "^3.0.2", - "jest": "^24.1.0", - "np": "^5.0.0", - "redux": "^4.0.1", - "ts-jest": "^24.0.0", - "tslint": "^5.12.1", - "tslint-ionic-rules": "0.0.21" + "@stencil/core": "1.12.2", + "redux": "^4.0.1" }, "peerDependencies": { "redux": "^4.0.1" diff --git a/src/components.d.ts b/src/components.d.ts index 162096c..83eed8c 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -1,45 +1,24 @@ +/* eslint-disable */ /* tslint:disable */ /** * This is an autogenerated file created by the Stencil compiler. * It contains typing information for all components that exist in this project. */ - - -import '@stencil/core'; - - - - +import { HTMLStencilElement, JSXBase } from "@stencil/core/internal"; export namespace Components { - } - declare global { - interface StencilElementInterfaces { - - } - - interface StencilIntrinsicElements { - - } - - - - interface HTMLElementTagNameMap { - - } - - interface ElementTagNameMap { - - } - - - export namespace JSX { - export interface Element {} - export interface IntrinsicElements extends StencilIntrinsicElements { - [tagName: string]: any; + interface HTMLElementTagNameMap { + } +} +declare namespace LocalJSX { + interface IntrinsicElements { + } +} +export { LocalJSX as JSX }; +declare module "@stencil/core" { + export namespace JSX { + interface IntrinsicElements { + } } - } - export interface HTMLAttributes extends StencilHTMLAttributes {} - } diff --git a/src/global/interfaces.ts b/src/global/interfaces.ts index 97d7618..96d6614 100644 --- a/src/global/interfaces.ts +++ b/src/global/interfaces.ts @@ -1,6 +1,6 @@ -import { Action, AnyAction, Store as ReduxStore, Unsubscribe } from 'redux'; +import { Action as ReduxAction, AnyAction, Store as ReduxStore, Unsubscribe } from 'redux'; -export interface Store { +export interface Store { getState: () => S; getStore: () => ReduxStore; setStore: (store: ReduxStore) => void; From 0d844239e52e56e1a9c832fb9cb24e6701a786e2 Mon Sep 17 00:00:00 2001 From: Edward Silverton Date: Mon, 25 May 2020 09:55:49 +0100 Subject: [PATCH 3/3] re-add linting, fix jest test --- package.json | 10 +++++++++- test/global/store.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bcbf6f5..d4dba4d 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,15 @@ }, "devDependencies": { "@stencil/core": "1.12.2", - "redux": "^4.0.1" + "@types/jest": "^24.0.5", + "@types/redux": "^3.6.0", + "husky": "^3.0.2", + "jest": "^24.1.0", + "np": "^5.0.0", + "redux": "^4.0.1", + "ts-jest": "^24.0.0", + "tslint-ionic-rules": "0.0.21", + "tslint": "^5.12.1" }, "peerDependencies": { "redux": "^4.0.1" diff --git a/test/global/store.ts b/test/global/store.ts index fd518cc..12b8090 100644 --- a/test/global/store.ts +++ b/test/global/store.ts @@ -1,4 +1,5 @@ import { createStore } from 'redux'; + import { Store } from '../../src/global/interfaces'; declare global { @@ -6,13 +7,16 @@ declare global { interface Global { Context: { store: Store; - } + }; } } } (global as any).Context = {}; -import '../../src/global/store'; + +import { default as ReduxStore } from '../../src/global/store'; + +ReduxStore(); describe('@stencil/redux', () => {