Skip to content

Commit

Permalink
Use serialization with lazy-loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Jan 12, 2023
1 parent 565a84d commit 2d249d7
Show file tree
Hide file tree
Showing 25 changed files with 555 additions and 370 deletions.
127 changes: 94 additions & 33 deletions flipper-plugin-realm/src/CommonTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
// A helper interface which extends Realm.Object with
// a string index signature and object key field for reference.
export interface IndexableRealmObject extends Realm.Object {
[key: string]: unknown;
// Contains the object key that was sent by the device.
_pluginObjectKey: string;
export type PlainRealmObject = Record<string, unknown>

/**
* An interface containing refereence information about a Realm object sent
* from the device plugin.
*/
export interface RealmObjectReference {
// The object key of the stored Realm object
objectKey: string;
objectType: string;
}

// A Realm.CanonicalObjectSchema interface with a sorting order field.
/**
* An interface for receiving and sending Realm Objects between
* the desktop plugin and the device.
* @see DeserializedRealmObject
**/
export interface SerializedRealmObject extends RealmObjectReference {
// Result of serializaing a Realm object from flatted.toJSON(realmObject.toJSON())
realmObject: never;
}

/**
* A helper interface which wraps Realm.Object with
* information about its object type and key for reference.
* @see SerializedRealmObject
**/
export interface DeserializedRealmObject extends RealmObjectReference {
// A plain representation of the Realm object
realmObject: PlainRealmObject;
}

/** A Realm.CanonicalObjectSchema interface with a sorting order field. */
export interface SortedObjectSchema extends Realm.CanonicalObjectSchema {
order: string[];
}
Expand All @@ -21,7 +45,7 @@ export type RealmPluginState = {
deviceSerial: string;
realms: string[];
selectedRealm: string;
objects: IndexableRealmObject[];
objects: DeserializedRealmObject[];
schemas: SortedObjectSchema[];
currentSchema: SortedObjectSchema | null;
schemaHistory: SortedObjectSchema[];
Expand All @@ -37,22 +61,23 @@ export type RealmPluginState = {
};

export type Events = {
getObjects: ObjectsMessage;
getSchemas: SchemaMessage;
getObjects: GetObjectsResponse;
getSchemas: GetSchemasResponse;
liveObjectAdded: AddLiveObjectRequest;
liveObjectDeleted: DeleteLiveObjectRequest;
liveObjectEdited: EditLiveObjectRequest;
getCurrentQuery: undefined;
getRealms: RealmsMessage;
getRealms: GetRealmResponse;
executeQuery: QueryResult;
};
export type Methods = {
executeQuery: (query: QueryObject) => Promise<Realm.Object[]>;
getObjects: (data: getForwardsObjectsRequest) => Promise<ObjectsMessage>;
getSchemas: (data: RealmRequest) => Promise<SchemaMessage>;
getRealms: () => Promise<RealmsMessage>;
addObject: (object: AddObject) => Promise<Realm.Object>;
modifyObject: (newObject: EditObject) => Promise<Realm.Object>;
getObjects: (data: GetObjectsRequest) => Promise<GetObjectsResponse>;
getObject: (data: GetObjectRequest) => Promise<SerializedRealmObject>;
getSchemas: (data: GetSchemasRequest) => Promise<GetSchemasResponse>;
getRealms: () => Promise<GetRealmResponse>;
addObject: (object: AddObjectsRequest) => Promise<PlainRealmObject>;
modifyObject: (newObject: EditObject) => Promise<PlainRealmObject>;
removeObject: (object: RemoveObject) => Promise<void>;
receivedCurrentQuery: (request: {
schema: string | null;
Expand All @@ -73,46 +98,49 @@ type DataDownloadRequest = {
export type EditObject = {
schema?: string;
realm?: string;
object: Realm.Object;
object: PlainRealmObject;
propsChanged?: string[];
objectKey: string;
};

export type RemoveObject = {
schema?: string;
realm?: string;
object: Realm.Object;
object: PlainRealmObject;
objectKey: string;
};

export type AddObject = {
export type AddObjectsRequest = {
schema?: string;
realm?: string;
object: Realm.Object;
object: PlainRealmObject;
propsChanged?: string[];
};
export type RealmsMessage = {
export type GetRealmResponse = {
realms: string[];
objects: Record<string, unknown>[];
total: number;
};
export type ObjectsMessage = {
objects: IndexableRealmObject[];
total: number;
nextCursor: string;
prev_cursor: { [sortingField: string]: number };
hasMore: boolean;
};

export type ObjectMessage = {
object: Realm.Object;
};
export type SchemaMessage = {

type GetSchemasRequest = {
realm: string;
};

export type GetSchemasResponse = {
schemas: Array<Realm.CanonicalObjectSchema>;
};
type RealmRequest = {

type GetObjectRequest = {
schema: string;
realm: string;
objectKey: string;
};
type getForwardsObjectsRequest = {

export type GetObjectsRequest = {
schema: string;
realm: string;
cursor: string | null;
Expand All @@ -121,13 +149,21 @@ type getForwardsObjectsRequest = {
query: string;
};

export type GetObjectsResponse = {
objects: SerializedRealmObject[];
total: number;
nextCursor: string;
prev_cursor: { [sortingField: string]: number };
hasMore: boolean;
};

export type ObjectRequest = {
schema: string;
realm: string;
primaryKey: string;
};
export type AddLiveObjectRequest = {
newObject: IndexableRealmObject;
newObject: SerializedRealmObject;
index: number;
schema: string;
newObjectKey: string;
Expand All @@ -137,7 +173,7 @@ export type DeleteLiveObjectRequest = {
schema: string;
};
export type EditLiveObjectRequest = {
newObject: IndexableRealmObject;
newObject: SerializedRealmObject;
index: number;
schema: string;
newObjectKey: string;
Expand All @@ -150,3 +186,28 @@ type QueryObject = {
export type QueryResult = {
result: Array<Realm.Object> | string;
};


export type MenuItem = {
key: number;
text: string;
onClick: () => void;
};

export type MenuItemGenerator = (
row: DeserializedRealmObject,
schemaProperty: Realm.CanonicalObjectSchemaProperty,
schema: Realm.ObjectSchema,
) => Array<MenuItem>;

export type DropdownPropertyType = {
record: DeserializedRealmObject | null;
schemaProperty: Realm.CanonicalObjectSchemaProperty | null;
currentSchema: Realm.ObjectSchema;
visible: boolean;
pointerX: number;
pointerY: number;
scrollX: number;
scrollY: number;
generateMenuItems: MenuItemGenerator;
};
26 changes: 1 addition & 25 deletions flipper-plugin-realm/src/components/CustomDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
import React, { useState } from 'react';
import { theme } from 'flipper-plugin';
import { IndexableRealmObject } from '../CommonTypes';

export type DropdownPropertyType = {
record: IndexableRealmObject | null;
schemaProperty: Realm.CanonicalObjectSchemaProperty | null;
currentSchema: Realm.ObjectSchema;
visible: boolean;
pointerX: number;
pointerY: number;
scrollX: number;
scrollY: number;
generateMenuItems: MenuItemGenerator;
};

type MenuItem = {
key: number;
text: string;
onClick: () => void;
};

export type MenuItemGenerator = (
row: IndexableRealmObject,
schemaProperty: Realm.CanonicalObjectSchemaProperty,
schema: Realm.ObjectSchema,
) => Array<MenuItem>;
import { DropdownPropertyType, MenuItem } from '../CommonTypes';

const listItem = (menuItem: MenuItem) => {
const [hover, setHover] = useState(false);
Expand Down
Loading

0 comments on commit 2d249d7

Please sign in to comment.