Skip to content

Commit

Permalink
rename TriggerEvent to NativebrikEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
RyosukeCla committed Oct 20, 2023
1 parent ff864cb commit 36239fd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ios/Nativebrik/Classes/repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class ExperimentConfigsRepository {
self.cache = cacheStrategy
}

func trigger(event: TriggerEvent, callback: @escaping (_ entry: Entry<ExperimentConfigsData>) -> Void) async {
func trigger(event: NativebrikEvent, callback: @escaping (_ entry: Entry<ExperimentConfigsData>) -> Void) async {
let url = self.config.cdnUrl + "/projects/" + self.config.projectId + "/experiments/trigger/" + event.name
await self._fetch(key: event.name, url: url, callback: callback)
}
Expand Down
4 changes: 2 additions & 2 deletions ios/Nativebrik/Classes/sdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public struct ComponentEvent {
public let payload: [EventProperty]?
}

public struct TriggerEvent {
public struct NativebrikEvent {
public let name: String
public init(_ name: String) {
self.name = name
Expand Down Expand Up @@ -166,7 +166,7 @@ public class NativebrikClient: ObservableObject {
return OverlayViewControllerRepresentable(overlayVC: self.overlayVC).frame(width: 0, height: 0)
}

public func dispatch(event: TriggerEvent) {
public func dispatch(event: NativebrikEvent) {
self.overlayVC.triggerViewController.dispatch(event: event)
}
}
Expand Down
20 changes: 10 additions & 10 deletions ios/Nativebrik/Classes/trigger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ class TriggerViewController: UIViewController {
self.didLoaded = true

// dispatch an event when the user is only booted
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.USER_BOOT_APP.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.USER_BOOT_APP.rawValue))

// dispatch user enter the app firtly
let count = UserDefaults.standard.object(forKey: UserDefaultsKeys.SDK_INITIALIZED_COUNT.rawValue) as? Int ?? 0
UserDefaults.standard.set(count + 1, forKey: UserDefaultsKeys.SDK_INITIALIZED_COUNT.rawValue)
if count == 0 {
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.USER_ENTER_TO_APP_FIRSTLY.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.USER_ENTER_TO_APP_FIRSTLY.rawValue))
}

// dispatch retention event
Expand All @@ -57,31 +57,31 @@ class TriggerViewController: UIViewController {
}

@objc func willEnterForeground() {
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.USER_ENTER_TO_FOREGROUND.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.USER_ENTER_TO_FOREGROUND.rawValue))
self.callWhenUserComeBack()
}

func callWhenUserComeBack() {
self.user.comeBack()

// dispatch the event when every time the user is activated
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.USER_ENTER_TO_APP.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.USER_ENTER_TO_APP.rawValue))

let retention = self.user.retention
if retention == 1 {
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.RETENTION_1.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.RETENTION_1.rawValue))
} else if 1 < retention && retention <= 3 {
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.RETENTION_2_3.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.RETENTION_2_3.rawValue))
} else if 3 < retention && retention <= 7 {
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.RETENTION_4_7.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.RETENTION_4_7.rawValue))
} else if 7 < retention && retention <= 14 {
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.RETENTION_8_14.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.RETENTION_8_14.rawValue))
} else if 14 < retention {
self.dispatch(event: TriggerEvent(TriggerEventNameDefs.RETENTION_15.rawValue))
self.dispatch(event: NativebrikEvent(TriggerEventNameDefs.RETENTION_15.rawValue))
}
}

func dispatch(event: TriggerEvent) {
func dispatch(event: NativebrikEvent) {
DispatchQueue.global().async {
Task {
if event.name.isEmpty {
Expand Down

0 comments on commit 36239fd

Please sign in to comment.