Skip to content

Commit

Permalink
bug fix: when experimentId is alised id, repository will fetch wrong …
Browse files Browse the repository at this point in the history
…data
  • Loading branch information
RyosukeCla committed Sep 28, 2023
1 parent 6af4b20 commit e783fee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,8 @@ Morondava is a charming coastal town located on the western coast of Madagascar.
ScrollView(.vertical) {
nativebrik
.experiment
.embedding("cjjei1223akg00bptlh0")
.embedding("TOP_COMPONENT")
.frame(width: nil, height: 270)
nativebrik
.experiment
.remoteConfigAsView("cjm5piq23akg008u0km0") { phase in
switch phase {
case .failure:
Text("error")
case .loading:
Text("loading")
case .completed(let variant):
Text(variant.getAsString("text") ?? "Not Found")
}
}
ForEach(self.items, id: \.title) { item in
item.padding()
}
Expand Down
17 changes: 13 additions & 4 deletions ios/Nativebrik/Classes/embedding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,19 @@ class EmbeddingUIView: ComponentUIView {
self?.renderFallback(phase: .failure)
return
}
guard let experimentConfigId = config.id else {
self?.renderFallback(phase: .failure)
return
}

repositories.track.trackExperimentEvent(
TrackExperimentEvent(
experimentId: experimentId,
experimentId: experimentConfigId,
variantId: variantId
)
)

self?.loadAndTransition(experimentId: experimentId, componentId: componentId)
self?.loadAndTransition(experimentId: experimentConfigId, componentId: componentId)
}
}
}
Expand All @@ -98,6 +102,7 @@ class EmbeddingSwiftViewModel: ComponentSwiftViewModel {
self?.phase = .failure
return
}
print("hello", experimentId, configs)
guard let experimentConfig = extractExperimentConfigMatchedToProperties(configs: configs, properties: { seed in
return self?.user.toEventProperties(seed: seed) ?? []
}) else {
Expand All @@ -121,16 +126,20 @@ class EmbeddingSwiftViewModel: ComponentSwiftViewModel {
self?.phase = .failure
return
}
guard let experimentConfigId = experimentConfig.id else {
self?.phase = .failure
return
}

repositories.track.trackExperimentEvent(
TrackExperimentEvent(
experimentId: experimentId,
experimentId: experimentConfigId,
variantId: variantId
)
)

self?.fetchComponentAndUpdatePhase(
experimentId: experimentId,
experimentId: experimentConfigId,
componentId: componentId,
config: config,
repositories: repositories,
Expand Down
8 changes: 6 additions & 2 deletions ios/Nativebrik/Classes/remote-config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,20 @@ public class RemoteConfig {
phase(.failure)
return
}
guard let experimentConfigId = config.id else {
phase(.failure)
return
}

self.repositories.track.trackExperimentEvent(
TrackExperimentEvent(
experimentId: self.experimentId,
experimentId: experimentConfigId,
variantId: variantId
)
)

phase(.completed(RemoteConfigVariant(
experimentId: experimentId,
experimentId: experimentConfigId,
variantId: variantId,
configs: variantConfigs,
config: self.config,
Expand Down

0 comments on commit e783fee

Please sign in to comment.