Skip to content

Commit d311c29

Browse files
authored
[AMSDK-11201] - Differentiate XDM vs standard shared state via eventName (adobe#593)
1 parent e3ea968 commit d311c29

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

AEPCore/Sources/eventhub/EventHub.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ final class EventHub {
180180
}
181181

182182
sharedState.set(version: version, data: data)
183-
self.dispatch(event: self.createSharedStateEvent(extensionName: extensionName))
183+
self.dispatch(event: self.createSharedStateEvent(extensionName: extensionName, sharedStatetype: sharedStateType))
184184
Log.debug(label: self.LOG_TAG, "\(sharedStateType.rawValue.capitalized) shared state created for \(extensionName) with version \(version) and data: \n\(PrettyDictionary.prettify(data))")
185185
}
186186
}
@@ -284,7 +284,7 @@ final class EventHub {
284284

285285
let version = sharedState.resolve(version: 0).value == nil ? 0 : eventNumberCounter.incrementAndGet()
286286
sharedState.set(version: version, data: data)
287-
dispatch(event: createSharedStateEvent(extensionName: EventHubConstants.NAME))
287+
dispatch(event: createSharedStateEvent(extensionName: EventHubConstants.NAME, sharedStatetype: .standard))
288288
Log.debug(label: LOG_TAG, "Shared state created for \(EventHubConstants.NAME) with version \(version) and data: \n\(PrettyDictionary.prettify(data))")
289289
}
290290

@@ -328,14 +328,15 @@ final class EventHub {
328328
guard let pendingVersion = version, let container = registeredExtensions.first(where: { $1.sharedStateName.caseInsensitiveCompare(extensionName) == .orderedSame })?.value else { return }
329329
guard let sharedState = container.sharedState(for: sharedStateType) else { return }
330330
sharedState.updatePending(version: pendingVersion, data: data)
331-
dispatch(event: createSharedStateEvent(extensionName: container.sharedStateName))
331+
dispatch(event: createSharedStateEvent(extensionName: container.sharedStateName, sharedStatetype: sharedStateType))
332332
}
333333

334334
/// Creates a template `Event` for `SharedState` of the provided `extensionName`
335335
/// - Parameter extensionName: A `String` containing the name of the extension
336336
/// - Returns: An empty `SharedState` `Event` for the provided `extensionName`
337-
private func createSharedStateEvent(extensionName: String) -> Event {
338-
return Event(name: EventHubConstants.STATE_CHANGE, type: EventType.hub, source: EventSource.sharedState,
337+
private func createSharedStateEvent(extensionName: String, sharedStatetype: SharedStateType) -> Event {
338+
let eventName = sharedStatetype == .standard ? EventHubConstants.STATE_CHANGE : EventHubConstants.XDM_STATE_CHANGE
339+
return Event(name: eventName, type: EventType.hub, source: EventSource.sharedState,
339340
data: [EventHubConstants.EventDataKeys.Configuration.EVENT_STATE_OWNER: extensionName])
340341
}
341342

AEPCore/Sources/eventhub/EventHubConstants.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import Foundation
1313

1414
/// Constant values used throughout `EventHub`
1515
enum EventHubConstants {
16-
static let STATE_CHANGE = "STATE_CHANGE_EVENT"
16+
static let STATE_CHANGE = "Shared state change"
17+
static let XDM_STATE_CHANGE = "Shared state change (XDM)"
1718
static let NAME = "com.adobe.module.eventhub"
1819
static let FRIENDLY_NAME = "EventHub"
1920
static let VERSION_NUMBER = "3.1.0"

AEPCore/Tests/EventHubTests/EventHubTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,8 +1027,8 @@ class EventHubTests: XCTestCase {
10271027

10281028
let event = Event(name: "test", type: EventType.acquisition, source: EventSource.requestContent, data: nil)
10291029
eventHub.getExtensionContainer(MockExtension.self)?.registerListener(type: EventType.hub, source: EventSource.sharedState) { event in
1030-
XCTAssertEqual(event.name, EventHubConstants.STATE_CHANGE)
10311030
if event.data?[EventHubConstants.EventDataKeys.Configuration.EVENT_STATE_OWNER] as! String == EventHubTests.MOCK_EXTENSION_NAME {
1031+
XCTAssertEqual(event.name, EventHubConstants.STATE_CHANGE)
10321032
expectation.fulfill()
10331033
}
10341034
}
@@ -1052,8 +1052,8 @@ class EventHubTests: XCTestCase {
10521052

10531053
let event = Event(name: "test", type: EventType.acquisition, source: EventSource.requestContent, data: nil)
10541054
eventHub.getExtensionContainer(MockExtension.self)?.registerListener(type: EventType.hub, source: EventSource.sharedState) { event in
1055-
XCTAssertEqual(event.name, EventHubConstants.STATE_CHANGE)
10561055
if event.data?[EventHubConstants.EventDataKeys.Configuration.EVENT_STATE_OWNER] as! String == EventHubTests.MOCK_EXTENSION_NAME {
1056+
XCTAssertEqual(event.name, EventHubConstants.XDM_STATE_CHANGE)
10571057
expectation.fulfill()
10581058
}
10591059
}

AEPCore/Tests/FunctionalTests/EventHubContractTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class EventHubContractTest: XCTestCase {
124124
let sharedStateEventExpectation = XCTestExpectation(description: "Event Hub shared stated event is received")
125125
ContractExtensionOne.eventReceivedClosure = { event in
126126
switch event.name{
127-
case "STATE_CHANGE_EVENT":
127+
case "Shared state change":
128128
sharedStateEventExpectation.fulfill()
129129
default:
130130
XCTAssertFalse(true)
@@ -156,7 +156,7 @@ class EventHubContractTest: XCTestCase {
156156
firstEventExpectation.fulfill()
157157
case "second":
158158
secondEventExpectation.fulfill()
159-
case "STATE_CHANGE_EVENT":
159+
case "Shared state change":
160160
sharedStateEventExpectation.fulfill()
161161
default:
162162
XCTAssertFalse(true)

0 commit comments

Comments
 (0)