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';
|
||||
import {FlipperPlugin} from 'flipper';
|
||||
|
||||
const {clone} = require('lodash');
|
||||
import {clone} from 'lodash';
|
||||
|
||||
type SharedPreferencesChangeEvent = {|
|
||||
preferences: string,
|
||||
@@ -97,8 +97,12 @@ export default class extends FlipperPlugin<SharedPreferencesState> {
|
||||
entry.preferences = update.preferences;
|
||||
state.sharedPreferences[update.name] = entry;
|
||||
return {
|
||||
...state,
|
||||
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) {
|
||||
return state;
|
||||
}
|
||||
let newEntry;
|
||||
if (change.deleted) {
|
||||
delete entry.preferences[change.name];
|
||||
const newPreferences = {
|
||||
...entry.preferences,
|
||||
};
|
||||
delete newPreferences[change.name];
|
||||
newEntry = {
|
||||
...entry,
|
||||
preferences: newPreferences,
|
||||
};
|
||||
} 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 {
|
||||
selectedPreferences: state.selectedPreferences,
|
||||
sharedPreferences: state.sharedPreferences,
|
||||
...state,
|
||||
sharedPreferences: {
|
||||
...state.sharedPreferences,
|
||||
[change.preferences]: newEntry,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -125,6 +146,7 @@ export default class extends FlipperPlugin<SharedPreferencesState> {
|
||||
event: Object,
|
||||
) {
|
||||
return {
|
||||
...state,
|
||||
selectedPreferences: event.selected,
|
||||
sharedPreferences: state.sharedPreferences,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user