mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
switch to immutable js
This commit is contained in:
parent
2534e38fcf
commit
f9d19d9b79
@ -32,6 +32,7 @@
|
|||||||
},
|
},
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"debug": "^2.2.0",
|
||||||
"immutability-helper": "^2.0.0",
|
"immutability-helper": "^2.0.0",
|
||||||
"immutable": "^3.8.1",
|
"immutable": "^3.8.1",
|
||||||
"normalize.css": "^4.2.0",
|
"normalize.css": "^4.2.0",
|
||||||
|
@ -16,10 +16,7 @@ export default class FeatureList extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
// TODO: only fetch from server if we don't know about any toggles.
|
this.props.fetchFeatureToggles();
|
||||||
if (this.props.features.length === 0) {
|
|
||||||
this.props.fetchFeatureToggles();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
@ -3,7 +3,7 @@ import { toggleFeature, fetchFeatureToggles } from '../../store/feature-actions'
|
|||||||
import FeatureList from './FeatureList';
|
import FeatureList from './FeatureList';
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
features: state.features,
|
features: state.features.toJS(),
|
||||||
});
|
});
|
||||||
|
|
||||||
const mapDispatchToProps = {
|
const mapDispatchToProps = {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import api from './feature-api';
|
import api from './feature-api';
|
||||||
|
const debug = require('debug')('unleash:feature-actions');
|
||||||
|
|
||||||
export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE';
|
export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE';
|
||||||
export const UPDATE_FEATURE_TOGGLE = 'UPDATE_FEATURE_TOGGLE';
|
export const UPDATE_FEATURE_TOGGLE = 'UPDATE_FEATURE_TOGGLE';
|
||||||
@ -42,6 +43,7 @@ function errorUpdatingFeatureToggle (statusCode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function toggleFeature (featureToggle) {
|
export function toggleFeature (featureToggle) {
|
||||||
|
debug('Toggle feature toggle ', featureToggle);
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
const newValue = Object.assign({}, featureToggle, { enabled: !featureToggle.enabled });
|
const newValue = Object.assign({}, featureToggle, { enabled: !featureToggle.enabled });
|
||||||
dispatch(requestUpdateFeatureToggle(newValue));
|
dispatch(requestUpdateFeatureToggle(newValue));
|
||||||
@ -84,6 +86,7 @@ function errorReceiveFeatureToggles (statusCode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fetchFeatureToggles () {
|
export function fetchFeatureToggles () {
|
||||||
|
debug('Start fetching feature toggles');
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestFeatureToggles());
|
dispatch(requestFeatureToggles());
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Immutable from 'immutable';
|
import { List, Map } from 'immutable';
|
||||||
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ADD_FEATURE_TOGGLE,
|
ADD_FEATURE_TOGGLE,
|
||||||
@ -6,23 +7,21 @@ import {
|
|||||||
UPDATE_FEATURE_TOGGLE,
|
UPDATE_FEATURE_TOGGLE,
|
||||||
} from './feature-actions';
|
} from './feature-actions';
|
||||||
|
|
||||||
const features = (state = [], action) => {
|
|
||||||
|
const features = (state = new List([]), action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ADD_FEATURE_TOGGLE:
|
case ADD_FEATURE_TOGGLE:
|
||||||
return [
|
return state.push(new Map(action.featureToggle));
|
||||||
...state,
|
|
||||||
action.featureToggle,
|
|
||||||
];
|
|
||||||
case UPDATE_FEATURE_TOGGLE:
|
case UPDATE_FEATURE_TOGGLE:
|
||||||
return state.map(t => {
|
return state.map(t => {
|
||||||
if (t.name !== action.featureToggle.name) {
|
if (t.get('name') === action.featureToggle.name) {
|
||||||
|
return new Map(action.featureToggle);
|
||||||
|
} else {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
return action.featureToggle;
|
|
||||||
});
|
});
|
||||||
case RECEIVE_FEATURE_TOGGLES: {
|
case RECEIVE_FEATURE_TOGGLES:
|
||||||
return action.featureToggles;
|
return new List(action.featureToggles.map(t => new Map(t)));
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user