Summary: Fixed issue https://github.com/facebook/flipper/issues/470 ## Changelog Producing new state when preferences gets updated in SharedPreferences plugin Pull Request resolved: https://github.com/facebook/flipper/pull/623 Reviewed By: mweststrate Differential Revision: D18929828 Pulled By: passy fbshipit-source-id: 8e9e61f90838fd3676aa52c4c6117b3f452aa7c0
This commit is contained in:
committed by
Facebook Github Bot
parent
838fb7b274
commit
559285f5f9
@@ -20,7 +20,7 @@ import {
|
|||||||
} from 'flipper';
|
} from 'flipper';
|
||||||
import {FlipperPlugin} from 'flipper';
|
import {FlipperPlugin} from 'flipper';
|
||||||
|
|
||||||
const {clone} = require('lodash');
|
import {clone} from 'lodash';
|
||||||
|
|
||||||
type SharedPreferencesChangeEvent = {|
|
type SharedPreferencesChangeEvent = {|
|
||||||
preferences: string,
|
preferences: string,
|
||||||
@@ -97,8 +97,12 @@ export default class extends FlipperPlugin<SharedPreferencesState> {
|
|||||||
entry.preferences = update.preferences;
|
entry.preferences = update.preferences;
|
||||||
state.sharedPreferences[update.name] = entry;
|
state.sharedPreferences[update.name] = entry;
|
||||||
return {
|
return {
|
||||||
|
...state,
|
||||||
selectedPreferences: state.selectedPreferences || update.name,
|
selectedPreferences: state.selectedPreferences || update.name,
|
||||||
sharedPreferences: state.sharedPreferences,
|
sharedPreferences: {
|
||||||
|
...state.sharedPreferences,
|
||||||
|
[update.name]: entry,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -108,15 +112,32 @@ export default class extends FlipperPlugin<SharedPreferencesState> {
|
|||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
let newEntry;
|
||||||
if (change.deleted) {
|
if (change.deleted) {
|
||||||
delete entry.preferences[change.name];
|
const newPreferences = {
|
||||||
|
...entry.preferences,
|
||||||
|
};
|
||||||
|
delete newPreferences[change.name];
|
||||||
|
newEntry = {
|
||||||
|
...entry,
|
||||||
|
preferences: newPreferences,
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
entry.preferences[change.name] = change.value;
|
newEntry = {
|
||||||
|
...entry,
|
||||||
|
preferences: {
|
||||||
|
...entry.preferences,
|
||||||
|
[change.name]: change.value,
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
entry.changesList = [change, ...entry.changesList];
|
newEntry.changesList = [change, ...entry.changesList];
|
||||||
return {
|
return {
|
||||||
selectedPreferences: state.selectedPreferences,
|
...state,
|
||||||
sharedPreferences: state.sharedPreferences,
|
sharedPreferences: {
|
||||||
|
...state.sharedPreferences,
|
||||||
|
[change.preferences]: newEntry,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -125,6 +146,7 @@ export default class extends FlipperPlugin<SharedPreferencesState> {
|
|||||||
event: Object,
|
event: Object,
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
|
...state,
|
||||||
selectedPreferences: event.selected,
|
selectedPreferences: event.selected,
|
||||||
sharedPreferences: state.sharedPreferences,
|
sharedPreferences: state.sharedPreferences,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user