Skip to content

Commit 5e2277f

Browse files
committed
Merge branch 'develop' into issue/9-fullfill-order
2 parents f0b882f + 4aa1e06 commit 5e2277f

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

WooCommerce/Classes/Authentication/Prologue/LoginPrologueViewController.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private extension LoginPrologueViewController {
7070
}
7171

7272
func setupUpperLabel() {
73-
upperLabel.text = NSLocalizedString("Check your WooCommerce store on the go, fulfill your orders and get notifications of new sales.", comment: "Login Prologue Legend")
73+
upperLabel.text = NSLocalizedString("Your WooCommerce store on the go. Check your sales, fulfill your orders, and get notifications of new sales.", comment: "Login Prologue Legend")
7474
upperLabel.font = UIFont.font(forStyle: .subheadline, weight: .bold)
7575
upperLabel.textColor = .white
7676
}
@@ -135,19 +135,23 @@ private extension LoginPrologueViewController {
135135
/// Returns the Disclaimer Attributed Text (which contains a link to the Jetpack Setup URL).
136136
///
137137
var disclaimerAttributedText: NSAttributedString {
138-
let disclaimerText = NSLocalizedString("This app requires Jetpack to be able to connect to your WooCommerce Store.\nFor configuration instructions, ", comment: "Login Disclaimer Text")
138+
let disclaimerText = NSLocalizedString("This app requires Jetpack to be able to connect to your WooCommerce Store.\nRead the ", comment: "Login Disclaimer Text and Jetpack config instructions")
139139
let disclaimerAttributes: [NSAttributedStringKey: Any] = [
140140
.font: UIFont.font(forStyle: .caption1, weight: .thin),
141141
.foregroundColor: UIColor.black
142142
]
143143

144-
let readText = NSLocalizedString("read here.", comment: "Login Disclaimer Linked Text")
144+
let readText = NSLocalizedString("configuration instructions", comment: "Login Disclaimer Linked Text")
145145
var readAttributes = disclaimerAttributes
146146
readAttributes[.link] = URL(string: WooConstants.jetpackSetupUrl)
147-
148147
let readAttrText = NSMutableAttributedString(string: readText, attributes: readAttributes)
148+
149+
let endSentenceText = "."
150+
let endSentenceAttrText = NSMutableAttributedString(string: endSentenceText, attributes: disclaimerAttributes)
151+
149152
let disclaimerAttrText = NSMutableAttributedString(string: disclaimerText, attributes: disclaimerAttributes)
150153
disclaimerAttrText.append(readAttrText)
154+
disclaimerAttrText.append(endSentenceAttrText)
151155

152156
return disclaimerAttrText
153157
}

Yosemite/Yosemite/Base/Dispatcher.swift

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Dispatcher {
2525

2626
/// Collection of active Action Processors, per action kind.
2727
///
28-
private(set) var processors = [Action.TypeIdentifier: ActionsProcessor]()
28+
private var processors = [Action.TypeIdentifier: WeakProcessor]()
2929

3030

3131
/// Designated Initializer
@@ -41,7 +41,7 @@ public class Dispatcher {
4141
fatalError("An action type can only be handled by a single processor!")
4242
}
4343

44-
processors[actionType.identifier] = processor
44+
processors[actionType.identifier] = WeakProcessor(processor: processor)
4545
}
4646

4747
/// Unregisters the specified Processor from *ALL* of the dispatcher queues.
@@ -60,6 +60,12 @@ public class Dispatcher {
6060
return processors[actionType.identifier]?.identifier == processor.identifier
6161
}
6262

63+
/// Returns the registered ActionsProcessor, for a specified Action, if any exist.
64+
///
65+
public func processor(for actionType: Action.Type) -> ActionsProcessor? {
66+
return processors[actionType.identifier]?.processor
67+
}
68+
6369
/// Dispatches the given action to all registered processors.
6470
///
6571
public func dispatch(_ action: Action) {
@@ -68,3 +74,31 @@ public class Dispatcher {
6874
processors[action.identifier]?.onAction(action)
6975
}
7076
}
77+
78+
79+
// MARK: - WeakProcessor: Allows us to weakly-store ActionProcessors, and thus, prevent retain cycles.
80+
//
81+
private class WeakProcessor {
82+
83+
/// The actual ActionsProcessor we're proxying.
84+
///
85+
private(set) weak var processor: ActionsProcessor?
86+
87+
/// Returns the internal Processor's Identifier, if any.
88+
///
89+
var identifier: ActionsProcessor.TypeIdentifier? {
90+
return processor?.identifier
91+
}
92+
93+
/// Designated Initializer
94+
///
95+
init(processor: ActionsProcessor) {
96+
self.processor = processor
97+
}
98+
99+
/// Called whenever a given Action is dispatched.
100+
///
101+
func onAction(_ action: Action) {
102+
processor?.onAction(action)
103+
}
104+
}

Yosemite/YosemiteTests/Base/DispatcherTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,14 @@ class DispatcherTests: XCTestCase {
6565
dispatcher.dispatch(MockupAccountAction.authenticate)
6666
XCTAssertEqual(processor.receivedActions.count, 1)
6767
}
68+
69+
/// Verifies that the Dispatcher does not strongly retain the ActionsProcessors.
70+
///
71+
func testProcessorsAreNotStronglyRetainedByDispatcher() {
72+
dispatcher.register(processor: processor, for: SiteAction.self)
73+
XCTAssertNotNil(dispatcher.processor(for: SiteAction.self))
74+
processor = nil
75+
76+
XCTAssertNil(dispatcher.processor(for: SiteAction.self))
77+
}
6878
}

0 commit comments

Comments
 (0)