Skip to content
This repository was archived by the owner on Jan 26, 2021. It is now read-only.

Commit 35acbea

Browse files
committed
Introduce Flow type for object change descriptor issued by the ObjectStore
1 parent 3120256 commit 35acbea

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/ObjectStore.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ export type IdWithOrderingInfo = {
3636
ordering: OrderingInfo;
3737
};
3838
export type FlattenedObjectData = { [attr: string]: any };
39+
export type ObjectChangeDescriptor = {
40+
id: Id;
41+
latest: any; // TODO: this should really be FlattenedObjectData
42+
fields?: Array<string>;
43+
};
3944

4045
/**
4146
* ObjectStore is a local cache for Parse Objects. It stores the last known
@@ -175,7 +180,11 @@ function destroyMutationStack(target: Id) {
175180
* Returns the latest object state and an array of keys that changed, or null
176181
* in the case of a Destroy
177182
*/
178-
function resolveMutation(target: Id, payloadId: number, delta: Delta): { id: Id; latest: any; fields?: Array<string> } {
183+
function resolveMutation(
184+
target: Id,
185+
payloadId: number,
186+
delta: Delta
187+
): ObjectChangeDescriptor {
179188
var stack = pendingMutations[target];
180189
var i;
181190
for (i = 0; i < stack.length; i++) {
@@ -226,8 +235,7 @@ function resolveMutation(target: Id, payloadId: number, delta: Delta): { id: Id;
226235
* Returns the latest object state and an array of keys that changed, or null
227236
* in the case of a Destroy
228237
*/
229-
function commitDelta(delta: Delta):
230-
{ id: Id; latest: any; fields?: Array<string> } {
238+
function commitDelta(delta: Delta): ObjectChangeDescriptor {
231239
var id = delta.id;
232240
if (delta.destroy) {
233241
if (store[id]) {

src/UpdateChannel.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,13 @@ function performOptimisticMutation(
123123
* fetch a list of potential new subscribers using the changed fields, and add
124124
* the object to the result sets of any queries that now match.
125125
*/
126-
function pushUpdates(subscribers: Array<string>, changes: { id: Id; latest: any; fields?: Array<string> }) {
126+
function pushUpdates(
127+
subscribers: Array<string>,
128+
// TODO: we really want to use the ObjectChangeDescriptor type alias from
129+
// ObjectStore here, but importing it will cause a bunch of additional Flow
130+
// checks to happen that we're not ready for yet.
131+
changes: { id: Id; latest: any; fields?: Array<string> }
132+
) {
127133
var i;
128134
if (changes.latest === null) {
129135
// Pushing a Destroy action. Remove it from all current subscribers

0 commit comments

Comments
 (0)