Skip to content

Commit

Permalink
fix the flipper plugin implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kitakkun committed Jul 6, 2024
1 parent e10a7d0 commit c808ac4
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 26 deletions.
3 changes: 2 additions & 1 deletion backintime-flipper-plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
dist/
.idea/*
!.idea/codeStyles
*.tgz
*.tgz
*.map
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ test(`notifyMethodCall event`, () => {

sendEvent("notifyMethodCall", {
methodName: "hoge",
ownerClassFqName: "com.example.MyClass",
instanceUUID: "7fd43b42-f951-4307-a997-85f6074c17c9",
methodCallUUID: "jf245181-8d9f-4d9e-9a7b-1a7f4b6f0b3e",
calledAt: 1619813420,
Expand All @@ -80,6 +81,7 @@ test(`notifyMethodCall event`, () => {

expect(state.methodCallInfoList[0]).toEqual({
instanceUUID: "7fd43b42-f951-4307-a997-85f6074c17c9",
ownerClassFqName: "com.example.MyClass",
methodName: "hoge",
callUUID: "jf245181-8d9f-4d9e-9a7b-1a7f4b6f0b3e",
calledAt: 1619813420,
Expand All @@ -97,14 +99,16 @@ test(`notifyValueChange event`, () => {

sendEvent("notifyMethodCall", {
methodName: "hoge",
ownerClassFqName: "com.example.MyClass",
instanceUUID: instanceUUID,
methodCallUUID: methodCallUUID,
calledAt: calledAt,
} as NotifyMethodCall);

sendEvent("notifyValueChange", {
instanceUUID: instanceUUID,
propertyFqName: "hoge",
ownerClassFqName: "com.example.MyClass",
propertyName: "hoge",
value: "fuga",
methodCallUUID: methodCallUUID,
} as NotifyValueChange);
Expand All @@ -116,7 +120,7 @@ test(`notifyValueChange event`, () => {
calledAt: calledAt,
valueChanges: [
{
propertyFqName: "hoge",
propertyName: "hoge",
value: "fuga",
}
],
Expand Down
4 changes: 3 additions & 1 deletion backintime-flipper-plugin/src/data/MethodCallInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface MethodCallInfo {
ownerClassFqName: string;
callUUID: string;
instanceUUID: string;
methodName: string;
Expand All @@ -7,6 +8,7 @@ export interface MethodCallInfo {
}

export interface ValueChangeInfo {
propertyFqName: string;
ownerClassFqName: string;
propertyName: string;
value: string;
}
4 changes: 3 additions & 1 deletion backintime-flipper-plugin/src/reducer/appReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const appSlice = createSlice({
registerMethodCall: (state, action: PayloadAction<BackInTimeDebugServiceEvent.NotifyMethodCall>) => {
const event = action.payload;
state.methodCallInfoList.push({
ownerClassFqName: event.ownerClassFqName,
callUUID: event.methodCallUUID,
instanceUUID: event.instanceUUID,
methodName: event.methodName,
Expand All @@ -97,7 +98,8 @@ const appSlice = createSlice({
const methodCallInfo = state.methodCallInfoList.find((info) => info.callUUID == event.methodCallUUID);
if (!methodCallInfo) return;
methodCallInfo.valueChanges.push({
propertyFqName: event.propertyFqName,
ownerClassFqName: event.ownerClassFqName,
propertyName: event.propertyName,
value: event.value,
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ export function BackInTimeModalPage() {
.filter((history) => history.title == "methodCall")
.map((history) => history as MethodCallHistoryInfo);
const allValueChanges = methodCallHistories.flatMap((history) => history.valueChanges);
const properties = distinctBy(allValueChanges.map((valueChange) => valueChange.propertyFqName), (name) => name);
properties.forEach((name) => {
const value = allValueChanges.reverse().find((valueChange) => valueChange.propertyFqName == name)?.value;
if (!value) return;
const propertyValueChanges = distinctBy(allValueChanges.reverse(), (valueChange) => valueChange.ownerClassFqName + valueChange.propertyName);
propertyValueChanges.forEach((info) => {
const event = new BackInTimeDebuggerEvent.ForceSetPropertyValue(
state.instanceUUID,
name,
value,
"", // 使われてないから大丈夫
info.ownerClassFqName,
info.propertyName,
info.value,
);
dispatch(appActions.forceSetPropertyValue(event));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const backInTimeStateSelector = createSelector(
title: "methodCall",
timestamp: info.calledAt,
subtitle: info.methodName,
description: info.valueChanges.map((change) => `${change.propertyFqName} = ${change.value}`).join(", "),
description: info.valueChanges.map((change) => `${change.propertyName} = ${change.value}`).join(", "),
valueChanges: info.valueChanges,
} as HistoryInfo;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export function EditAndEmitValueModalPage() {
cancelText={"Cancel"}
okText={"Emit Edited Value"}
onOk={() => {
if (!state.instanceUUID || !state.propertyName || !state.valueType) return;
if (!state.instanceUUID || !state.propertyName || !state.valueType || !state.ownerClassFqName) return;
const event = new BackInTimeDebuggerEvent.ForceSetPropertyValue(
state.instanceUUID,
state.ownerClassFqName,
state.propertyName,
JSON.stringify(state.editingValue),
state.valueType,
);
dispatch(appActions.forceSetPropertyValue(event));
dispatch(editAndEmitValueActions.close());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const editAndEmitValueStateSelector = createSelector(
return {
...state,
valueType: valueType,
ownerClassFqName: classInfo?.name,
} as EditAndEmitState;
}
);
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface EditAndEmitState {
editingValue: any;
open: boolean;
instanceUUID: string;
ownerClassFqName: string;
propertyName: string;
valueType: string | undefined;
}
Expand All @@ -34,4 +35,4 @@ export function EditAndEmitValueView({state, onEdit}: EditAndEmitValueViewProps)
</Layout.Container>
</Layout.Horizontal>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export function InstanceListPage() {
onClickRefresh={() => {
const uuids = state.instances.map((info) => info.uuid);
if (uuids.length == 0) return;
const event = createCheckInstanceAliveEvent(uuids);
dispatch(appActions.refreshInstanceAliveStatuses(event));
dispatch(appActions.refreshInstanceAliveStatuses(createCheckInstanceAliveEvent(uuids)));
}}
onChangeNonDebuggablePropertyVisible={(visible) => {
dispatch(persistentStateActions().updateNonDebuggablePropertyVisibility(visible));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function resolveInstanceInfo(
name: property.name,
type: property.type,
debuggable: property.debuggable,
eventCount: allValueChangeEvents.filter((event) => event.propertyFqName == `${classInfo.name}.${property.name}`).length,
eventCount: allValueChangeEvents.filter((event) => event.propertyName == property.name && classInfo.name == event.ownerClassFqName).length,
stateHolderInstance: propertyInstanceInfo && resolveInstanceInfo(
classInfoList,
instanceInfoList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ValueChangeItem = {
export function ChangedPropertiesView({classInfo, methodCallInfo, onClickEmitValue, onClickEditAndEmitValue}: ChangedPropertiesViewProps) {
const dataSource: ValueChangeItem[] = methodCallInfo.valueChanges.map((valueChange) => {
// FIXME: will not work correctly for the class which has a back-in-time debuggable class as a super class.
const property = classInfo.properties.find((property) => property.name === valueChange.propertyFqName.split(".").pop())!;
const property = classInfo.properties.find((property) => property.name === valueChange.propertyName)!;
const jsonValue = JSON.parse(valueChange.value);
return {
action: <EmitButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ export function ValueEmitModalPage() {
onValueEmit={(propertyName: string, value: string) => {
const instanceUUID = state.instanceInfo?.uuid;
const valueType = state.classInfo?.properties.find((property) => property.name == propertyName)?.valueType;
if (!instanceUUID || !valueType) {
const className = state.classInfo?.name
if (!instanceUUID || !valueType || !className) {
return;
}
const propertyFqName = `${state.classInfo?.name}.${propertyName}`;
const event = new BackInTimeDebuggerEvent.ForceSetPropertyValue(instanceUUID, propertyFqName, value, valueType);
const event = new BackInTimeDebuggerEvent.ForceSetPropertyValue(instanceUUID, className, propertyName, value);
dispatch(appActions.forceSetPropertyValue(event));
}}
onEditAndEmitValue={(propertyName: string, value: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export const propertyInspectorStateSelector = createSelector(

const valueChanges = methodCallInfoList.filter((info) =>
// FIXME: will not work correctly for the class which has a back-in-time debuggable class as a super class.
info.instanceUUID == state.instanceUUID && info.valueChanges.some((change) => change.propertyFqName.split(".").pop() == state.propertyName)
info.instanceUUID == state.instanceUUID && info.valueChanges.some((change) => change.propertyName.split(".").pop() == state.propertyName)
).map((info) => {
return {
methodCallUUID: info.callUUID,
time: info.calledAt,
// FIXME: will not work correctly for the class which has a back-in-time debuggable class as a super class.
value: [...info.valueChanges].reverse().find((change) => change.propertyFqName.split(".").pop() == state.propertyName)?.value ?? "",
value: [...info.valueChanges].reverse().find((change) => change.propertyName.split(".").pop() == state.propertyName)?.value ?? "",
}
});

Expand Down

0 comments on commit c808ac4

Please sign in to comment.