Receive navigation events and persist them
Summary: After setting up the navigation event emitter on the android side, we must now receive them on the client side and persist them in the Redux store. Reviewed By: passy Differential Revision: D16280944 fbshipit-source-id: 3dc4c5c6add41388469c801700974eb0ccd9a56b
This commit is contained in:
committed by
Facebook Github Bot
parent
ce93ecfcca
commit
a9e90aa9b2
@@ -13,8 +13,13 @@ type State = {||};
|
|||||||
|
|
||||||
type Data = {||};
|
type Data = {||};
|
||||||
|
|
||||||
|
type NavigationEvent = {|
|
||||||
|
date: Date,
|
||||||
|
uri: ?String,
|
||||||
|
|};
|
||||||
|
|
||||||
type PersistedState = {|
|
type PersistedState = {|
|
||||||
data: Array<Data>,
|
navigationEvents: [NavigationEvent],
|
||||||
|};
|
|};
|
||||||
|
|
||||||
export default class extends FlipperPlugin<State, {}, PersistedState> {
|
export default class extends FlipperPlugin<State, {}, PersistedState> {
|
||||||
@@ -24,18 +29,28 @@ export default class extends FlipperPlugin<State, {}, PersistedState> {
|
|||||||
static keyboardActions = ['clear'];
|
static keyboardActions = ['clear'];
|
||||||
|
|
||||||
static defaultPersistedState: PersistedState = {
|
static defaultPersistedState: PersistedState = {
|
||||||
data: [],
|
navigationEvents: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
static persistedStateReducer = (
|
static persistedStateReducer = (
|
||||||
persistedState: PersistedState,
|
persistedState: PersistedState,
|
||||||
method: string,
|
method: string,
|
||||||
data: Data,
|
payload: Object,
|
||||||
): $Shape<PersistedState> => {
|
): $Shape<PersistedState> => {
|
||||||
|
switch (method) {
|
||||||
|
case 'nav_event':
|
||||||
return {
|
return {
|
||||||
...persistedState,
|
...persistedState,
|
||||||
data: persistedState.data.concat([data]),
|
navigationEvents: [
|
||||||
|
...persistedState.navigationEvents,
|
||||||
|
{uri: payload.uri, date: new Date()},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
...persistedState,
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onKeyboardAction = (action: string) => {
|
onKeyboardAction = (action: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user