Skip to content

Commit 09eaedf

Browse files
committed
update
1 parent 477fc0f commit 09eaedf

17 files changed

+64
-64
lines changed

Sources/PureMVC/core/View.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,17 @@ open class View: IView {
184184
- parameter mediator: a reference to the `IMediator` instance
185185
*/
186186
open func registerMediator(_ mediator: IMediator) {
187-
// do not allow re-registration (you must removeMediator first)
188-
if hasMediator(mediator.name) { return }
189-
190-
mediator.initializeNotifier(multitonKey)
191-
192-
mediatorMapQueue.sync(flags: .barrier) {
193-
// Register the Mediator for retrieval by name
187+
let exists = mediatorMapQueue.sync(flags: .barrier) {
188+
guard mediatorMap[mediator.name] == nil else { return true }
194189
mediatorMap[mediator.name] = mediator
190+
return false
195191
}
192+
193+
if exists { return }
194+
195+
mediator.initializeNotifier(multitonKey)
196196

197-
// Create Observer referencing this mediator's handlNotification method
197+
// Create Observer referencing this mediator's handleNotification method
198198
let observer = Observer(notifyMethod: mediator.handleNotification, notifyContext: mediator)
199199

200200
let interests = mediator.listNotificationInterests()

Sources/PureMVC/interfaces/IMediator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public protocol IMediator: INotifier {
4040
var name: String { get }
4141

4242
/// Get or set the `IMediator`'s view component.
43-
var viewComponent: AnyObject? { get set }
43+
var view: AnyObject? { get set }
4444

4545
/**
4646
List `INotification` interests.

Sources/PureMVC/patterns/command/MacroCommand.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ open class MacroCommand: Notifier, ICommand {
9595
public final func execute(_ notification: INotification) {
9696
while (!subCommands.isEmpty) {
9797
let factory = subCommands.remove(at: 0)
98-
let commandInstance = factory()
99-
commandInstance.initializeNotifier(multitonKey!)
100-
commandInstance.execute(notification)
98+
let command = factory()
99+
command.initializeNotifier(multitonKey!)
100+
command.execute(notification)
101101
}
102102
}
103103

Sources/PureMVC/patterns/mediator/Mediator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ open class Mediator: Notifier, IMediator {
2626
public private(set) var name: String
2727

2828
// The view component
29-
public weak var viewComponent: AnyObject?
29+
public weak var view: AnyObject?
3030

3131
/**
3232
Constructor.
3333

3434
- parameter name: the mediator name
3535
- parameter viewComponent: viewComponent instance
3636
*/
37-
public init(name: String? = nil, viewComponent: AnyObject? = nil) {
37+
public init(name: String? = nil, view: AnyObject? = nil) {
3838
self.name = name ?? Mediator.NAME
39-
self.viewComponent = viewComponent
39+
self.view = view
4040
}
4141

4242
/**

Tests/PureMVCTests/core/ViewExtendTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ViewExtendTest: XCTestCase {
4545
let resource = Resource()
4646
var viewExtend: ViewExtend! = (ViewExtend.getInstance(key: "Key1") as! ViewExtend)
4747

48-
viewExtend.registerMediator(ResourceMediator(viewComponent: resource))
48+
viewExtend.registerMediator(ResourceMediator(view: resource))
4949

5050
View.removeView("Key1")
5151
viewExtend = nil

Tests/PureMVCTests/core/ViewTest.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public class ViewTest: XCTestCase {
112112
let view = View.getInstance("ViewTestKey3") { key in View(key: key) }
113113

114114
// Create and register the test mediator
115-
let viewTestMediator = ViewTestMediator(viewComponent: self)
115+
let viewTestMediator = ViewTestMediator(view: self)
116116
view?.registerMediator(viewTestMediator)
117117

118118
// Retrieve the component
@@ -131,7 +131,7 @@ public class ViewTest: XCTestCase {
131131
let view: IView? = View.getInstance("ViewTestKey4") { key in View(key: key) }
132132

133133
// Create and register the test mediator
134-
let mediator = Mediator(name: "hasMediatorTest", viewComponent: self)
134+
let mediator = Mediator(name: "hasMediatorTest", view: self)
135135
view?.registerMediator(mediator)
136136

137137
// assert that the view?hasMediator method returns true
@@ -153,7 +153,7 @@ public class ViewTest: XCTestCase {
153153
let view: IView? = View.getInstance("ViewTestKey5") { key in View(key: key) }
154154

155155
// Create and register the test mediator
156-
let mediator: IMediator = Mediator(name: "testing", viewComponent: self)
156+
let mediator: IMediator = Mediator(name: "testing", view: self)
157157
view?.registerMediator(mediator)
158158

159159
// Remove the component
@@ -174,7 +174,7 @@ public class ViewTest: XCTestCase {
174174
let view: IView? = View.getInstance("ViewTestKey6") { key in View(key: key) }
175175

176176
// Create and register the test mediator
177-
let mediator: IMediator = ViewTestMediator4(viewComponent: self)
177+
let mediator: IMediator = ViewTestMediator4(view: self)
178178
view?.registerMediator(mediator)
179179

180180
// assert that onRegsiter was called, and the mediator responded by setting our boolean
@@ -196,7 +196,7 @@ public class ViewTest: XCTestCase {
196196

197197
// Create and register the test mediator,
198198
// but not so we have a reference to it
199-
view?.registerMediator(ViewTestMediator(viewComponent: self))
199+
view?.registerMediator(ViewTestMediator(view: self))
200200

201201
// test that we can retrieve it
202202
XCTAssertTrue(view?.retrieveMediator(ViewTestMediator.NAME) is ViewTestMediator, "Expecting view?.retrieveMediator(ViewTestMediator.NAME) is ViewTestMediator")
@@ -211,7 +211,7 @@ public class ViewTest: XCTestCase {
211211
XCTAssertTrue(view?.removeMediator(ViewTestMediator.NAME) == nil, "Expecting view?.removeMediator( ViewTestMediator.NAME ) doesn't crash")
212212

213213
// Create and register another instance of the test mediator,
214-
view?.registerMediator(ViewTestMediator(viewComponent: self))
214+
view?.registerMediator(ViewTestMediator(view: self))
215215

216216
XCTAssertTrue(view?.retrieveMediator(ViewTestMediator.NAME) is ViewTestMediator, "Expecting view?.retrieveMediator( ViewTestMediator.NAME ) is ViewTestMediator")
217217

@@ -232,7 +232,7 @@ public class ViewTest: XCTestCase {
232232
let view: IView? = View.getInstance("ViewTestKey8") { key in View(key: key) }
233233

234234
// Create and register the test mediator to be removed.
235-
view?.registerMediator(ViewTestMediator2(viewComponent: self))
235+
view?.registerMediator(ViewTestMediator2(view: self))
236236

237237
// test that notifications work
238238
view?.notifyObservers(Notification(name: ViewTest.NOTE1))
@@ -270,10 +270,10 @@ public class ViewTest: XCTestCase {
270270
let view: IView? = View.getInstance("ViewTestKey9") { key in View(key: key) }
271271

272272
// Create and register that responds to notifications 1 and 2
273-
view?.registerMediator(ViewTestMediator2(viewComponent: self))
273+
view?.registerMediator(ViewTestMediator2(view: self))
274274

275275
// Create and register that responds to notification 3
276-
view?.registerMediator(ViewTestMediator3(viewComponent: self))
276+
view?.registerMediator(ViewTestMediator3(view: self))
277277

278278
// test that all notifications work
279279
view?.notifyObservers(Notification(name: ViewTest.NOTE1))
@@ -319,10 +319,10 @@ public class ViewTest: XCTestCase {
319319
let view: IView? = View.getInstance("ViewTestKey10") { key in View(key: key) }
320320

321321
// Create and register that responds to notification 5
322-
view?.registerMediator(ViewTestMediator5(viewComponent: self))
322+
view?.registerMediator(ViewTestMediator5(view: self))
323323

324324
// try to register another instance of that mediator (uses the same NAME constant).
325-
view?.registerMediator(ViewTestMediator5(viewComponent: self))
325+
view?.registerMediator(ViewTestMediator5(view: self))
326326

327327
// test that the counter is only incremented once (mediator 5's response)
328328
counter = 0
@@ -357,14 +357,14 @@ public class ViewTest: XCTestCase {
357357
// by removing themselves, which will cause the observer list for that notification
358358
// to change. versions prior to MultiCore Version 2.0.5 will see every other mediator
359359
// fails to be notified.
360-
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/1", viewComponent: self))
361-
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/2", viewComponent: self))
362-
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/3", viewComponent: self))
363-
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/4", viewComponent: self))
364-
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/5", viewComponent: self))
365-
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/6", viewComponent: self))
366-
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/7", viewComponent: self))
367-
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/8", viewComponent: self))
360+
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/1", view: self))
361+
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/2", view: self))
362+
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/3", view: self))
363+
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/4", view: self))
364+
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/5", view: self))
365+
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/6", view: self))
366+
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/7", view: self))
367+
view?.registerMediator(ViewTestMediator6(name: ViewTestMediator6.NAME + "/8", view: self))
368368

369369
// clear the counter
370370
counter = 0

Tests/PureMVCTests/core/ViewTestMediator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class ViewTestMediator: Mediator {
2323
/**
2424
Constructor
2525
*/
26-
public init(viewComponent: AnyObject?) {
27-
super.init(name: ViewTestMediator.NAME, viewComponent: viewComponent)
26+
public init(view: AnyObject?) {
27+
super.init(name: ViewTestMediator.NAME, view: view)
2828
}
2929

3030
public override func listNotificationInterests() -> [String] {

Tests/PureMVCTests/core/ViewTestMediator2.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class ViewTestMediator2 : Mediator {
2323
/**
2424
Constructor
2525
*/
26-
public init(viewComponent: AnyObject?) {
27-
super.init(name: ViewTestMediator2.NAME, viewComponent: viewComponent)
26+
public init(view: AnyObject?) {
27+
super.init(name: ViewTestMediator2.NAME, view: view)
2828
}
2929

3030
public override func listNotificationInterests() -> [String] {
@@ -38,7 +38,7 @@ public class ViewTestMediator2 : Mediator {
3838
}
3939

4040
public var viewTest: ViewTest {
41-
return viewComponent as! ViewTest
41+
return view as! ViewTest
4242
}
4343

4444
}

Tests/PureMVCTests/core/ViewTestMediator3.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public class ViewTestMediator3: Mediator {
2323
/**
2424
Constructor
2525
*/
26-
public init(viewComponent: AnyObject?) {
27-
super.init(name: ViewTestMediator3.NAME, viewComponent: viewComponent)
26+
public init(view: AnyObject?) {
27+
super.init(name: ViewTestMediator3.NAME, view: view)
2828
}
2929

3030
// be sure that the mediator has some Observers created
@@ -38,7 +38,7 @@ public class ViewTestMediator3: Mediator {
3838
}
3939

4040
public var viewTest: ViewTest {
41-
return viewComponent as! ViewTest
41+
return view as! ViewTest
4242
}
4343

4444
}

Tests/PureMVCTests/core/ViewTestMediator4.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class ViewTestMediator4: Mediator {
2020
*/
2121
public override class var NAME: String { return "ViewTestMediator4" }
2222

23-
public init(viewComponent: AnyObject?) {
24-
super.init(name: ViewTestMediator4.NAME, viewComponent: viewComponent)
23+
public init(view: AnyObject?) {
24+
super.init(name: ViewTestMediator4.NAME, view: view)
2525
}
2626

2727
public override func onRegister() {
@@ -33,7 +33,7 @@ public class ViewTestMediator4: Mediator {
3333
}
3434

3535
public var viewTest: ViewTest {
36-
return viewComponent as! ViewTest
36+
return view as! ViewTest
3737
}
3838

3939
}

0 commit comments

Comments
 (0)