Skip to content

Commit

Permalink
feat: add preInsert and postInsert for identify call (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhao900914 authored Aug 23, 2022
1 parent 957b61a commit 44f5b03
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,34 @@ private Identify createIdentify(JSONObject userProperties) {
} else if ((Object)userPropertiesObj.get(key) instanceof JSONArray) {
identify.prepend(key, userPropertiesObj.getJSONArray(key));
}
case "$preInsert":
if ((Object)userPropertiesObj.get(key) instanceof Double){
identify.preInsert(key, userPropertiesObj.getDouble(key));
} else if ((Object)userPropertiesObj.get(key) instanceof Integer){
identify.preInsert(key, userPropertiesObj.getInt(key));
} else if ((Object)userPropertiesObj.get(key) instanceof Long) {
identify.preInsert(key, userPropertiesObj.getLong(key));
} else if ((Object)userPropertiesObj.get(key) instanceof String) {
identify.preInsert(key, userPropertiesObj.getString(key));
} else if ((Object)userPropertiesObj.get(key) instanceof JSONObject) {
identify.preInsert(key, userPropertiesObj.getJSONObject(key));
} else if ((Object)userPropertiesObj.get(key) instanceof JSONArray) {
identify.preInsert(key, userPropertiesObj.getJSONArray(key));
}
case "$postInsert":
if ((Object)userPropertiesObj.get(key) instanceof Double){
identify.postInsert(key, userPropertiesObj.getDouble(key));
} else if ((Object)userPropertiesObj.get(key) instanceof Integer){
identify.postInsert(key, userPropertiesObj.getInt(key));
} else if ((Object)userPropertiesObj.get(key) instanceof Long) {
identify.postInsert(key, userPropertiesObj.getLong(key));
} else if ((Object)userPropertiesObj.get(key) instanceof String) {
identify.postInsert(key, userPropertiesObj.getString(key));
} else if ((Object)userPropertiesObj.get(key) instanceof JSONObject) {
identify.postInsert(key, userPropertiesObj.getJSONObject(key));
} else if ((Object)userPropertiesObj.get(key) instanceof JSONArray) {
identify.postInsert(key, userPropertiesObj.getJSONArray(key));
}
case "$set":
if ((Object)userPropertiesObj.get(key) instanceof Double){
identify.set(key, userPropertiesObj.getDouble(key));
Expand Down
4 changes: 4 additions & 0 deletions ios/AmplitudeReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ class ReactNative: NSObject {
identify.append(key, value: value)
case "$prepend":
identify.prepend(key, value: value)
case "$preInsert":
identify.preInsert(key, value: value)
case "$postInsert":
identify.postInsert(key, value: value)
case "$set":
identify.set(key, value: value)
case "$setOnce":
Expand Down
14 changes: 14 additions & 0 deletions src/identify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export enum IdentifyOperation {
SET_ONCE = '$setOnce',
ADD = '$add',
APPEND = '$append',
PREINSERT = '$preInsert',
POSTINSERT = '$postInsert',
UNSET = '$unset',
}

Expand All @@ -16,6 +18,8 @@ export interface IdentifyPayload {
[IdentifyOperation.SET]?: Record<string, unknown>;
[IdentifyOperation.SET_ONCE]?: Record<string, unknown>;
[IdentifyOperation.APPEND]?: Record<string, unknown>;
[IdentifyOperation.PREINSERT]?: Record<string, unknown>;
[IdentifyOperation.POSTINSERT]?: Record<string, unknown>;
}

export class Identify {
Expand All @@ -26,6 +30,8 @@ export class Identify {
IdentifyOperation.SET_ONCE,
IdentifyOperation.ADD,
IdentifyOperation.APPEND,
IdentifyOperation.PREINSERT,
IdentifyOperation.POSTINSERT,
IdentifyOperation.UNSET,
];

Expand Down Expand Up @@ -53,6 +59,14 @@ export class Identify {
this.addOp(IdentifyOperation.APPEND, key, value);
}

preInsert(key: string, value: unknown): void {
this.addOp(IdentifyOperation.PREINSERT, key, value);
}

postInsert(key: string, value: unknown): void {
this.addOp(IdentifyOperation.POSTINSERT, key, value);
}

private addOp(op: IdentifyOperation, key: string, value: unknown): void {
if (!Identify.ALL_OPS.includes(op)) {
throw new Error(
Expand Down

0 comments on commit 44f5b03

Please sign in to comment.