Comparing version 4.0.0 to 4.1.0-0
@@ -11,2 +11,3 @@ /// <reference types="react" /> | ||
setFlagsAction(payload: Computable<Partial<T>>): SetFlagsAction<T>; | ||
getFlagsSelector<S extends ProviderProps<T>>(state: S): T; | ||
createFlagsReducer(initialFlags: Computable<T>): Reducer<Computable<T>, AnyAction>; | ||
@@ -13,0 +14,0 @@ ConnectedFlagsProvider: React.ComponentType<{}>; |
@@ -7,2 +7,3 @@ "use strict"; | ||
var merge_1 = __importDefault(require("lodash/merge")); | ||
var deep_computed_1 = __importDefault(require("deep-computed")); | ||
var react_redux_1 = require("react-redux"); | ||
@@ -16,5 +17,2 @@ var utils_1 = require("./utils"); | ||
} | ||
var mapStateToProps = function (state) { return ({ | ||
flags: state.flags | ||
}); }; | ||
function createReduxBindings(FlagsProvider) { | ||
@@ -27,2 +25,19 @@ function setFlagsAction(payload) { | ||
} | ||
function mapStateToProps(state) { | ||
return { | ||
flags: state.flags | ||
}; | ||
} | ||
var prevFlags = null; | ||
var prevComputed = null; | ||
function getFlagsSelector(state) { | ||
if (prevFlags !== null && | ||
prevComputed !== null && | ||
prevFlags === state.flags) { | ||
return prevComputed; | ||
} | ||
prevFlags = state.flags; | ||
prevComputed = deep_computed_1.default(state.flags); | ||
return prevComputed; | ||
} | ||
function createFlagsReducer(initialFlags) { | ||
@@ -42,2 +57,3 @@ return function (state, action) { | ||
setFlagsAction: setFlagsAction, | ||
getFlagsSelector: getFlagsSelector, | ||
createFlagsReducer: createFlagsReducer, | ||
@@ -44,0 +60,0 @@ ConnectedFlagsProvider: ConnectedFlagsProvider |
{ | ||
"name": "flag", | ||
"version": "4.0.0", | ||
"version": "4.1.0-0", | ||
"description": "Feature flagging made easy for React and Redux", | ||
@@ -29,3 +29,3 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"deep-computed": "^0.1.2", | ||
"deep-computed": "^0.2.0", | ||
"lodash": "^4.17.11", | ||
@@ -32,0 +32,0 @@ "useful-types": "^0.2.1" |
@@ -6,3 +6,3 @@ # Flag | ||
``` | ||
yarn add flag@next | ||
yarn add flag | ||
``` | ||
@@ -96,2 +96,3 @@ | ||
setFlagsAction, | ||
getFlagsSelector, | ||
createFlagsReducer, | ||
@@ -101,3 +102,8 @@ ConnectedFlagsProvider | ||
export { setFlagsAction, createFlagsReducer, ConnectedFlagsProvider }; | ||
export { | ||
setFlagsAction, | ||
getFlagsSelector, | ||
createFlagsReducer, | ||
ConnectedFlagsProvider | ||
}; | ||
``` | ||
@@ -247,3 +253,3 @@ | ||
// 👇 must use the "flags" key of your state | ||
flags: createFlagsReducuer(flags), | ||
flags: createFlagsReducer(flags), | ||
other: otherReducer | ||
@@ -253,2 +259,22 @@ }); | ||
### getFlagsSelector | ||
A selector to retrieve _computed_ flags from Redux state. It is not enough to say `state.flags` because `createFlagsReducer` does not eagerly evaluate computable flags. | ||
(Though I suppose if you don't use any computable flags, then you don't necessarily need this 🤷♂️.) | ||
```tsx | ||
// reducer.ts | ||
import { getFlagsSelector, MyFlags } from "./flags"; | ||
type State = { | ||
flags: MyFlags; | ||
// ... | ||
}; | ||
// ... | ||
export const getFlags = (state: State) => getFlagsSelector(state); | ||
``` | ||
### ConnectedFlagsProvider | ||
@@ -255,0 +281,0 @@ |
import { AnyAction, Reducer } from "redux"; | ||
import merge from "lodash/merge"; | ||
import { Computable } from "deep-computed"; | ||
import deepComputed, { Computable } from "deep-computed"; | ||
import { ProviderProps } from "./create-flags"; | ||
@@ -23,8 +23,5 @@ import { connect } from "react-redux"; | ||
const mapStateToProps = <T>(state: ProviderProps<T>): ProviderProps<T> => ({ | ||
flags: state.flags | ||
}); | ||
export type CreateReduxBindings<T> = { | ||
setFlagsAction(payload: Computable<Partial<T>>): SetFlagsAction<T>; | ||
getFlagsSelector<S extends ProviderProps<T>>(state: S): T; | ||
createFlagsReducer( | ||
@@ -46,2 +43,27 @@ initialFlags: Computable<T> | ||
function mapStateToProps<S extends ProviderProps<T>>( | ||
state: S | ||
): ProviderProps<T> { | ||
return { | ||
flags: state.flags | ||
}; | ||
} | ||
let prevFlags: Computable<T> | null = null; | ||
let prevComputed: T | null = null; | ||
function getFlagsSelector<S extends ProviderProps<T>>(state: S): T { | ||
if ( | ||
prevFlags !== null && | ||
prevComputed !== null && | ||
prevFlags === state.flags | ||
) { | ||
return prevComputed; | ||
} | ||
prevFlags = state.flags; | ||
prevComputed = deepComputed(state.flags); | ||
return prevComputed; | ||
} | ||
function createFlagsReducer(initialFlags: Computable<T>) { | ||
@@ -67,2 +89,3 @@ return ( | ||
setFlagsAction, | ||
getFlagsSelector, | ||
createFlagsReducer, | ||
@@ -69,0 +92,0 @@ ConnectedFlagsProvider |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
47299
727
319
2
+ Addeddeep-computed@0.2.0(transitive)
- Removeddeep-computed@0.1.3(transitive)
Updateddeep-computed@^0.2.0