Generate and send bogus data to changeset plugin
Summary: This hooks up the listeners that send events from the SectionTree to the desktop plugin. gradle build will fail until I release a new Litho version with D16120818 ChangesetDebug receives events on every valid changeset, it will parse the data into Flipper objects and pass it to the desktop client to render it. Right now this just sends an event with empty data Reviewed By: adityasharat Differential Revision: D16121473 fbshipit-source-id: eeef92cea7dae836861d417ed6a00fcb11901e78
This commit is contained in:
committed by
Facebook Github Bot
parent
5371d5bdce
commit
a952f988d6
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.facebook.flipper.plugins.sections;
|
||||
|
||||
import com.facebook.flipper.core.FlipperArray;
|
||||
import com.facebook.flipper.core.FlipperObject;
|
||||
import com.facebook.litho.sections.ChangesInfo;
|
||||
import com.facebook.litho.sections.ChangesetDebugConfiguration;
|
||||
import com.facebook.litho.sections.ChangesetDebugConfiguration.ChangesetDebugListener;
|
||||
import com.facebook.litho.sections.Section;
|
||||
import com.facebook.litho.sections.SectionsLogEventUtils;
|
||||
import com.facebook.litho.sections.SectionsLogEventUtils.ApplyNewChangeSet;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ChangesetDebug implements ChangesetDebugListener {
|
||||
|
||||
private static ChangesetListener sSectionsFlipperPlugin;
|
||||
private static ChangesetDebug sInstance;
|
||||
private static AtomicInteger sChangesetIdGenerator = new AtomicInteger();
|
||||
|
||||
public interface ChangesetListener {
|
||||
void onChangesetApplied(
|
||||
String name,
|
||||
boolean isAsync,
|
||||
String surfaceId,
|
||||
String id,
|
||||
FlipperArray tree,
|
||||
FlipperObject changesetData);
|
||||
}
|
||||
|
||||
public static void setListener(ChangesetListener listener) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ChangesetDebug(listener);
|
||||
ChangesetDebugConfiguration.setListener(sInstance);
|
||||
}
|
||||
}
|
||||
|
||||
private ChangesetDebug(ChangesetListener listener) {
|
||||
sSectionsFlipperPlugin = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangesetApplied(
|
||||
Section rootSection,
|
||||
Section oldSection,
|
||||
ChangesInfo changesInfo,
|
||||
String surfaceId,
|
||||
@ApplyNewChangeSet int attribution,
|
||||
String extra) {
|
||||
final FlipperArray.Builder tree = new FlipperArray.Builder();
|
||||
final FlipperObject.Builder changesetData = new FlipperObject.Builder();
|
||||
|
||||
final String sourceName = SectionsLogEventUtils.applyNewChangeSetSourceToString(attribution);
|
||||
|
||||
sSectionsFlipperPlugin.onChangesetApplied(
|
||||
sourceName + " " + extra,
|
||||
isEventAsync(attribution),
|
||||
surfaceId,
|
||||
sChangesetIdGenerator.incrementAndGet() + "-" + surfaceId,
|
||||
tree.build(),
|
||||
changesetData.build());
|
||||
}
|
||||
|
||||
private static boolean isEventAsync(@ApplyNewChangeSet int source) {
|
||||
switch (source) {
|
||||
case ApplyNewChangeSet.SET_ROOT_ASYNC:
|
||||
case ApplyNewChangeSet.UPDATE_STATE_ASYNC:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,13 @@
|
||||
*/
|
||||
package com.facebook.flipper.plugins.sections;
|
||||
|
||||
import com.facebook.flipper.core.FlipperArray;
|
||||
import com.facebook.flipper.core.FlipperConnection;
|
||||
import com.facebook.flipper.core.FlipperObject;
|
||||
import com.facebook.flipper.core.FlipperPlugin;
|
||||
import com.facebook.flipper.plugins.sections.ChangesetDebug.ChangesetListener;
|
||||
|
||||
public class SectionsFlipperPlugin implements FlipperPlugin {
|
||||
public class SectionsFlipperPlugin implements FlipperPlugin, ChangesetListener {
|
||||
|
||||
private FlipperConnection mConnection;
|
||||
|
||||
@@ -21,6 +24,7 @@ public class SectionsFlipperPlugin implements FlipperPlugin {
|
||||
@Override
|
||||
public void onConnect(FlipperConnection connection) throws Exception {
|
||||
mConnection = connection;
|
||||
ChangesetDebug.setListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -30,4 +34,70 @@ public class SectionsFlipperPlugin implements FlipperPlugin {
|
||||
public boolean runInBackground() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name Name of event
|
||||
* @param isAsync Whether the event was sync or async
|
||||
* @param surfaceId SectionTree tag
|
||||
* @param id Changeset generation unique id
|
||||
* @param tree Representation of the SectionTree hierarchy
|
||||
* @param changesetData Changeset information
|
||||
*/
|
||||
@Override
|
||||
public void onChangesetApplied(
|
||||
String name,
|
||||
boolean isAsync,
|
||||
String surfaceId,
|
||||
String id,
|
||||
FlipperArray tree,
|
||||
FlipperObject changesetData) {
|
||||
if (mConnection == null) {
|
||||
return;
|
||||
}
|
||||
mConnection.send(
|
||||
"addEvent",
|
||||
new FlipperObject.Builder()
|
||||
.put("id", id)
|
||||
.put("update_mode", isAsync ? 0 : 1)
|
||||
.put("reason", name)
|
||||
.put("surface_key", surfaceId)
|
||||
.put("tree_generation_timestamp", 10000) // TODO
|
||||
.put("stack_trace", new FlipperArray.Builder().build())
|
||||
.put("payload", new FlipperObject.Builder().build())
|
||||
.build());
|
||||
|
||||
mConnection.send(
|
||||
"updateTreeGenerationHierarchyGeneration",
|
||||
new FlipperObject.Builder()
|
||||
.put("id", id)
|
||||
.put("hierarchy_generation_timestamp", 10000) // TODO
|
||||
.put("hierarchy_generation_duration", 0) // TODO
|
||||
.put("tree", tree)
|
||||
.put("reason", name)
|
||||
.build());
|
||||
|
||||
// Not sure both CHANGESET_GENERATED and CHANGESET_APPLIED need to sent here, need
|
||||
// to investigate a bit more.
|
||||
mConnection.send(
|
||||
"updateTreeGenerationChangesetGeneration",
|
||||
new FlipperObject.Builder()
|
||||
.put("type", "CHANGESET_GENERATED")
|
||||
.put("identifier", id)
|
||||
.put("tree_generation_id", "" + id)
|
||||
.put("timestamp", 10000) // TODO
|
||||
.put("duration", 0) // TODO
|
||||
.put("changeset", changesetData)
|
||||
.build());
|
||||
|
||||
mConnection.send(
|
||||
"updateTreeGenerationChangesetApplication",
|
||||
new FlipperObject.Builder()
|
||||
.put("type", "CHANGESET_APPLIED")
|
||||
.put("identifier", id)
|
||||
.put("tree_generation_id", id)
|
||||
.put("timestamp", 10000) // TODO
|
||||
.put("duration", 0) // TODO
|
||||
.put("changeset", changesetData)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user