Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hooks-global-state

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hooks-global-state - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

dist/devtools.js

5

CHANGELOG.md

@@ -5,2 +5,7 @@ # Change Log

## [0.2.0] - 2018-11-09
### Changed
- Hacky/dirty Redux DevTools Extension support
- Fix type definition
## [0.1.0] - 2018-11-07

@@ -7,0 +12,0 @@ ### Changed

10

dist/index.js

@@ -10,2 +10,6 @@ "use strict";

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

@@ -140,3 +144,3 @@

var dispatch = createDispatch(stateItemMap, getState, reducer);
return {
return _objectSpread({
useGlobalState: function useGlobalState(name) {

@@ -147,5 +151,7 @@ return stateItemMap[name].hook();

dispatch: dispatch
};
}, reducer === null ? {
stateItemMap: stateItemMap
} : {});
};
exports.createStore = createStore;

4

examples/02_typescript/state.ts
import { createGlobalState } from '../../src/index';
const { useGlobalState } = createGlobalState({
export const { useGlobalState } = createGlobalState({
counter: 0,

@@ -11,3 +11,1 @@ person: {

});
export { useGlobalState };

@@ -18,3 +18,3 @@ import { createStore } from '../../src/index';

const { dispatch, useGlobalState } = createStore(
export const { dispatch, useGlobalState } = createStore(
(state, action: Action) => {

@@ -63,11 +63,1 @@ switch (action.type) {

);
export const useGlobalStateCounter = () => {
return useGlobalState('counter');
};
export const useGlobalStatePerson = () => {
return useGlobalState('person');
};
export { dispatch };
import { applyMiddleware, combineReducers } from 'redux';
import { createStore, Dispatch, Store } from '../../src/index';
import { ApplyMiddleware, createStore, Dispatch } from '../../src/index';
type State = {
counter: number,
person: {
age: number,
firstName: string,
lastName: string,
},
};
const initialState: State = {
const initialState = {
counter: 0,

@@ -23,2 +14,4 @@ person: {

type State = typeof initialState;
type Action = {

@@ -70,3 +63,3 @@ type: 'increment',

const logger = ({ getState }: Store<State, Action>) =>
const logger = ({ getState }: { getState: () => State }) =>
(next: Dispatch<Action>) => (action: Action) => {

@@ -81,16 +74,6 @@ // tslint:disable no-console

const { dispatch, useGlobalState } = createStore(
export const { dispatch, useGlobalState } = createStore(
reducer,
initialState,
applyMiddleware(logger),
(applyMiddleware as unknown as ApplyMiddleware<State, Action>)(logger),
);
export const useGlobalStateCounter = () => {
return useGlobalState('counter');
};
export const useGlobalStatePerson = () => {
return useGlobalState('person');
};
export { dispatch };
{
"name": "react-hooks-global-state",
"description": "Simple global state for React by Hooks API",
"version": "0.1.1",
"version": "0.2.0",
"author": "Daishi Kato",

@@ -26,3 +26,4 @@ "repository": {

"examples:reducer": "webpack-dev-server --entry ./examples/06_reducer/main.ts --content-base examples/06_reducer",
"examples:middleware": "webpack-dev-server --entry ./examples/07_middleware/main.ts --content-base examples/07_middleware"
"examples:middleware": "webpack-dev-server --entry ./examples/07_middleware/main.ts --content-base examples/07_middleware",
"examples:thunk": "webpack-dev-server --entry ./examples/08_thunk/main.ts --content-base examples/08_thunk"
},

@@ -46,2 +47,3 @@ "keywords": [

"@types/react-dom": "^16.0.9",
"@types/redux-logger": "^3.0.6",
"babel-core": "^7.0.0-bridge.0",

@@ -63,2 +65,4 @@ "babel-eslint": "^10.0.1",

"redux": "^4.0.1",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"ts-loader": "^5.3.0",

@@ -97,3 +101,4 @@ "tslint": "^5.11.0",

],
"react/prop-types": 0
"react/prop-types": 0,
"no-underscore-dangle": 0
}

@@ -100,0 +105,0 @@ },

@@ -105,1 +105,2 @@ react-hooks-global-state

- [An alternative to React Redux by React Hooks API (For both JavaScript and TypeScript)](https://medium.com/@dai_shi/an-alternative-to-react-redux-by-react-hooks-api-for-both-javascript-and-typescript-c5e9a351ba0b)
- [Redux middleware compatible React Hooks library for easy global state management](https://medium.com/@dai_shi/redux-middleware-compatible-react-hooks-library-for-easy-global-state-management-4fe73623e69e)
export type Update<T> = ((v: T) => T) | T;
export type SetGlobalState<S> = <N extends keyof S, T extends S[N]>(
export type SetGlobalState<S> = <N extends keyof S>(
name: N,
update: Update<T>,
update: Update<S[N]>,
) => void;

@@ -14,4 +14,3 @@

export type UseGlobalState<S> = <N extends keyof S>(name: N) =>
{ [K in keyof S]: N extends K ? HookResult<S[K]> : never }[keyof S];
export type UseGlobalState<S> = <N extends keyof S>(name: N) => HookResult<S[N]>;

@@ -41,1 +40,13 @@ export type Store<S, A> = {

export const createStore: CreateStore;
// for patch redux
export type MiddlewareAPI<S, A> = {
getState: () => S,
dispatch: Dispatch<A>,
};
export type Middleware<S, A> =
(store: MiddlewareAPI<S, A>) => (next: Dispatch<A>) => (action: A) => A;
export type ApplyMiddleware<S, A> = (...args: Array<Middleware<S, A>>) => Enhancer<S, A>;

@@ -94,3 +94,4 @@ import { useState, useEffect } from 'react';

dispatch,
...(reducer === null ? { stateItemMap } : {}), // for devtools.js
};
};

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc