UNPKG

@segment/analytics-react-native

Version:

The hassle-free way to add Segment analytics to your React-Native app.

72 lines (68 loc) 1.79 kB
import { PluginType, UpdateType } from '../types'; import { DestinationPlugin, WaitingPlugin } from '../plugin'; /** * Example WaitingPlugin that automatically resumes after 1 second. * Used for testing the waiting plugin mechanism. */ export class ExampleWaitingPlugin extends WaitingPlugin { type = PluginType.enrichment; tracked = false; configure(analytics) { super.configure(analytics); // Simulate async work (network, native module init, etc.) setTimeout(() => { this.resume(); }, 1000); } execute(event) { super.execute(event); this.tracked = true; return event; } } /** * Example WaitingPlugin that resumes after 3 seconds when settings are updated. * Mimics the Kotlin SDK's ExampleWaitingPlugin behavior. */ export class ExampleWaitingPlugin1 extends WaitingPlugin { type = PluginType.before; tracked = false; update(_settings, type) { if (type === UpdateType.initial) { // Simulate async initialization that takes 3 seconds setTimeout(() => { this.resume(); }, 3000); } } execute(event) { this.tracked = true; return event; } } /** * Example WaitingPlugin that requires manual resume() call. * Used for testing manual control of event processing. */ export class ManualResumeWaitingPlugin extends WaitingPlugin { type = PluginType.enrichment; tracked = false; configure(analytics) { super.configure(analytics); } execute(event) { this.tracked = true; return event; } } /** * Stub destination plugin for testing. * Always enabled and accepts all events. */ export class StubDestinationPlugin extends DestinationPlugin { key = 'StubDestination'; isEnabled(_event) { return true; } } //# sourceMappingURL=exampleWaitingPlugin.js.map