Summary:
Quick notes:
- This looks worse than it is. It adds mandatory parentheses to single argument lambdas. Lots of outrage on Twitter about it, personally I'm {emoji:1f937_200d_2642} about it.
- Space before function, e.g. `a = function ()` is now enforced. I like this because both were fine before.
- I added `eslint-config-prettier` to the config because otherwise a ton of rules conflict with eslint itself.
Close https://github.com/facebook/flipper/pull/915
Reviewed By: jknoxville
Differential Revision: D20594929
fbshipit-source-id: ca1c65376b90e009550dd6d1f4e0831d32cbff03
87 lines
2.0 KiB
TypeScript
87 lines
2.0 KiB
TypeScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import {produce} from 'immer';
|
|
import {remote} from 'electron';
|
|
import {Actions} from './';
|
|
|
|
export type TrackingEvent =
|
|
| {
|
|
type: 'WINDOW_FOCUS_CHANGE';
|
|
time: number;
|
|
isFocused: boolean;
|
|
}
|
|
| {type: 'PLUGIN_SELECTED'; time: number; plugin: string | null}
|
|
| {type: 'TIMELINE_START'; time: number; isFocused: boolean};
|
|
|
|
export type State = {
|
|
timeline: TrackingEvent[];
|
|
};
|
|
const INITAL_STATE: State = {
|
|
timeline: [
|
|
{
|
|
type: 'TIMELINE_START',
|
|
time: Date.now(),
|
|
isFocused: remote.getCurrentWindow().isFocused(),
|
|
},
|
|
],
|
|
};
|
|
|
|
export type Action =
|
|
| {
|
|
type: 'windowIsFocused';
|
|
payload: {isFocused: boolean; time: number};
|
|
}
|
|
| {type: 'CLEAR_TIMELINE'; payload: {time: number; isFocused: boolean}};
|
|
|
|
export default function reducer(
|
|
state: State = INITAL_STATE,
|
|
action: Actions,
|
|
): State {
|
|
if (action.type === 'CLEAR_TIMELINE') {
|
|
return {
|
|
...state,
|
|
timeline: [
|
|
{
|
|
type: 'TIMELINE_START',
|
|
time: action.payload.time,
|
|
isFocused: action.payload.isFocused,
|
|
},
|
|
],
|
|
};
|
|
} else if (action.type === 'windowIsFocused') {
|
|
return produce(state, (draft) => {
|
|
draft.timeline.push({
|
|
type: 'WINDOW_FOCUS_CHANGE',
|
|
time: action.payload.time,
|
|
isFocused: action.payload.isFocused,
|
|
});
|
|
});
|
|
} else if (action.type === 'SELECT_PLUGIN') {
|
|
return produce(state, (draft) => {
|
|
draft.timeline.push({
|
|
type: 'PLUGIN_SELECTED',
|
|
time: action.payload.time,
|
|
plugin: action.payload.selectedPlugin || null,
|
|
});
|
|
});
|
|
}
|
|
return state;
|
|
}
|
|
|
|
export function clearTimeline(time: number): Action {
|
|
return {
|
|
type: 'CLEAR_TIMELINE',
|
|
payload: {
|
|
time,
|
|
isFocused: remote.getCurrentWindow().isFocused(),
|
|
},
|
|
};
|
|
}
|