Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Setup linter
Browse files Browse the repository at this point in the history
  • Loading branch information
imhoffd committed Feb 17, 2019
1 parent fae8e0e commit e8bcf16
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
"dev": "stencil build --es5 --dev --watch --serve --no-open --debug",
"deploy": "np",
"start": "npm run dev",
"test": "jest"
"test": "jest",
"lint": "tslint --config tslint.json --project tsconfig.json"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint"
}
},
"repository": {
"type": "git",
Expand All @@ -23,9 +29,13 @@
"devDependencies": {
"@stencil/core": "^0.18.0",
"@types/jest": "^24.0.5",
"husky": "^1.3.1",
"jest": "^24.1.0",
"np": "^4.0.2",
"ts-jest": "^23.10.5"
"redux": "^4.0.1",
"ts-jest": "^23.10.5",
"tslint": "^5.12.1",
"tslint-ionic-rules": "0.0.21"
},
"peerDependencies": {
"redux": "^4.0.1"
Expand Down
8 changes: 4 additions & 4 deletions src/global/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export interface Store {
dispatch: (action: any, _: any) => any;
subscribe: (cb: Function) => any;
subscribe: (cb: (...args: any[]) => any) => any;
getState: () => any;
getStore: () => any;
setStore: (any: any) => void;
setStore: (store: any) => void;
mapStateToProps: (component: any, props: any) => () => void;
mapDispatchToProps: (component: any, props: any) => void;
};
}

export type Action = Function;
export type Action = (...args: any[]) => any;
30 changes: 15 additions & 15 deletions src/global/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@ import { Store } from './interfaces';

declare var Context: any;

Context.store = (function() {
Context.store = (() => {
let _store: Store;

function setStore(store: Store) {
const setStore = (store: Store) => {
_store = store;
}
};

function getState() {
const getState = () => {
return _store && _store.getState();
}
};

function getStore() {
const getStore = () => {
return _store;
}
};

function mapDispatchToProps(component: any, props: any) {
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), _store),
configurable: true,
enumerable: true
})
enumerable: true,
});
});
}
};

function mapStateToProps(component: any, mapState: Function) {
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 => {
let newPropValue = mergeProps[newPropName];
const newPropValue = mergeProps[newPropName];
component[newPropName] = newPropValue;
// TODO: can we define new props and still have change detection work?
});
Expand All @@ -44,13 +44,13 @@ Context.store = (function() {
_mapStateToProps(component, mapState);

return unsubscribe;
}
};

return {
getStore,
setStore,
getState,
mapDispatchToProps,
mapStateToProps
mapStateToProps,
} as Store;
})();
10 changes: 1 addition & 9 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
{
"rules": {
"semicolon": [true, "always"],
"curly": [true],
"quotemark": [true, "single", "jsx-double"],
"no-duplicate-variable": true,
"no-unused-variable": [
true
]
}
"extends": "tslint-ionic-rules/strict"
}

0 comments on commit e8bcf16

Please sign in to comment.