djinn-state-react
Advanced tools
Comparing version 1.4.0 to 2.0.1
@@ -1,3 +0,4 @@ | ||
import { Djinn, DjinnService } from 'djinn-state'; | ||
export declare const createUseService: (djinn: Djinn) => <T extends DjinnService>(service: new () => T) => T; | ||
import { Djinn } from 'djinn-state'; | ||
import { UseService } from './types'; | ||
export declare const createUseService: (djinn: Djinn) => UseService; | ||
//# sourceMappingURL=hooks.d.ts.map |
@@ -5,5 +5,5 @@ "use strict"; | ||
exports.createUseService = function (djinn) { | ||
return function (service) { return useService(service, djinn); }; | ||
return function (service) { return useService(djinn, service); }; | ||
}; | ||
var useService = function (service, djinn) { | ||
var useService = function (djinn, service) { | ||
var _serviceInstance = djinn.getService(service); | ||
@@ -10,0 +10,0 @@ var _a = react_1.useState(_serviceInstance.state), setState = _a[1]; |
@@ -1,5 +0,2 @@ | ||
export { createDjinnConnector } from './createDjinnConnector'; | ||
export { djinnConnector } from './djinnConnector'; | ||
export { DjinnConnection } from './DjinnConnection'; | ||
export { createUseService } from './hooks'; | ||
//# sourceMappingURL=index.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var createDjinnConnector_1 = require("./createDjinnConnector"); | ||
exports.createDjinnConnector = createDjinnConnector_1.createDjinnConnector; | ||
var djinnConnector_1 = require("./djinnConnector"); | ||
exports.djinnConnector = djinnConnector_1.djinnConnector; | ||
var DjinnConnection_1 = require("./DjinnConnection"); | ||
exports.DjinnConnection = DjinnConnection_1.DjinnConnection; | ||
var hooks_1 = require("./hooks"); | ||
exports.createUseService = hooks_1.createUseService; |
@@ -1,7 +0,3 @@ | ||
export declare type ServicesDescription = { | ||
[k: string]: any; | ||
}; | ||
export declare type ServiceStateMapping = { | ||
[k: string]: (state: any) => any; | ||
}; | ||
import { DjinnService } from 'djinn-state'; | ||
export declare type UseService = <T extends DjinnService>(service: new () => T) => T; | ||
//# sourceMappingURL=types.d.ts.map |
{ | ||
"name": "djinn-state-react", | ||
"version": "1.4.0", | ||
"version": "2.0.1", | ||
"description": "djinn-state helpers for react", | ||
@@ -22,3 +22,3 @@ "main": "dist/index.js", | ||
"test:ci": "jest --all --ci --coverage --color && yarn test:send-coverage", | ||
"build": "yarn build:ts", | ||
"build": "yarn rimraf ./dist && yarn build:ts", | ||
"build:ts": "tsc -p tsconfig.json", | ||
@@ -32,12 +32,10 @@ "test:send-coverage": "cat ./coverage/lcov.info | yarn codacy-coverage --language typescript" | ||
"devDependencies": { | ||
"@types/enzyme": "^3.1.15", | ||
"@types/enzyme-adapter-react-16": "^1.0.3", | ||
"@types/jest": "^23.3.10", | ||
"@types/react": "^16.7.18", | ||
"@types/react": "^16.8.5", | ||
"@types/react-dom": "^16.8.4", | ||
"codacy-coverage": "^3.3.0", | ||
"enzyme": "^3.8.0", | ||
"enzyme-adapter-react-16": "^1.7.1", | ||
"jest": "^23.6.0", | ||
"jest-enzyme": "^7.0.1", | ||
"react-dom": "^16.7.0", | ||
"jest-dom": "^3.1.4", | ||
"react-dom": "^16.8.6", | ||
"rimraf": "^2.6.3", | ||
"ts-jest": "^23.10.5", | ||
@@ -48,4 +46,5 @@ "tslint": "^5.12.0", | ||
"dependencies": { | ||
"djinn-state": "^1.3.1", | ||
"react": "^16.7.0" | ||
"@types/seamless-immutable": "^7.1.9", | ||
"djinn-state": "^2.0.0", | ||
"react": "^16.8.5" | ||
}, | ||
@@ -52,0 +51,0 @@ "typings": "dist/index.d.ts", |
@@ -44,3 +44,3 @@ # Djinn-state react | ||
decrement = () => { | ||
const count = this.state.count - 1; | ||
const count = this.getState().count - 1; | ||
this.patch({ count }); | ||
@@ -50,3 +50,3 @@ }; | ||
increment = () => { | ||
const count = this.state.count + 1; | ||
const count = this.getState().count + 1; | ||
this.patch({ count }); | ||
@@ -68,3 +68,3 @@ }; | ||
const HomePage = ({ services, state }) => { | ||
const HomePage = () => { | ||
const counter = useService(CounterService); | ||
@@ -75,3 +75,3 @@ | ||
<button onClick={counter.decrement}>-</button> | ||
{counter.state.count} | ||
{counter.getState().count} | ||
<button onClick={counter.increment}>+</button> | ||
@@ -78,0 +78,0 @@ </div> |
import { useEffect, useState } from 'react'; | ||
import { Djinn, DjinnService } from 'djinn-state'; | ||
import { UseService } from './types'; | ||
export const createUseService = (djinn: Djinn): UseService => | ||
<T extends DjinnService>(service: new () => T) => useService(djinn, service); | ||
export const createUseService = (djinn: Djinn) => | ||
<T extends DjinnService>(service: new () => T) => useService(service, djinn); | ||
const useService = <T extends DjinnService>(service: new () => T, djinn: Djinn): T => { | ||
const useService = <T extends DjinnService>(djinn: Djinn, service: new () => T): T => { | ||
const _serviceInstance = djinn.getService(service); | ||
@@ -13,3 +13,3 @@ const [, setState] = useState(_serviceInstance.state); | ||
useEffect(() => | ||
_serviceInstance.subscribe(() => setState({})), | ||
_serviceInstance.subscribe(() => setState({})), | ||
[]); | ||
@@ -16,0 +16,0 @@ |
@@ -1,4 +0,1 @@ | ||
export { createDjinnConnector } from './createDjinnConnector'; | ||
export { djinnConnector } from './djinnConnector'; | ||
export { DjinnConnection } from './DjinnConnection'; | ||
export { createUseService } from './hooks'; |
@@ -1,2 +0,3 @@ | ||
export type ServicesDescription = { [k: string]: any }; | ||
export type ServiceStateMapping = { [k: string]: (state: any) => any }; | ||
import { DjinnService } from 'djinn-state'; | ||
export type UseService = <T extends DjinnService>(service: new () => T) => T; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11
9394
3
17
108
1
+ Added@types/seamless-immutable@7.1.19(transitive)
+ Addeddjinn-state@2.0.0(transitive)
+ Addedseamless-immutable@7.1.4(transitive)
- Removeddjinn-state@1.3.1(transitive)
Updateddjinn-state@^2.0.0
Updatedreact@^16.8.5