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