Skip to content

Commit

Permalink
Updated recorders
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Usbergo committed Aug 10, 2017
1 parent e2378e8 commit 7bc5aeb
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 81 deletions.
2 changes: 1 addition & 1 deletion DispatchStore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "DispatchStore"
s.version = "0.4"
s.version = "0.5"
s.summary = "Multi-store Flux implementation in Swift."

# This description is used to generate tags and improve search results.
Expand Down
20 changes: 10 additions & 10 deletions DispatchStore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
/* Begin PBXBuildFile section */
1601D4241E8895B6008A2CF5 /* Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1601D4231E8895B6008A2CF5 /* Action.swift */; };
1601D4251E8895D3008A2CF5 /* Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1601D4231E8895B6008A2CF5 /* Action.swift */; };
162B39C11EC08DBF0074E075 /* RecorderMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16D979D11E88C4CB00F4430B /* RecorderMiddleware.swift */; };
1639E3E91EE2E27D00A3A182 /* PushID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3E81EE2E27D00A3A182 /* PushID.swift */; };
1639E3EA1EE2E2B900A3A182 /* PushID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3E81EE2E27D00A3A182 /* PushID.swift */; };
1639E3F01EE2E4A100A3A182 /* Serialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3EF1EE2E4A100A3A182 /* Serialization.swift */; };
1639E3F11EE2E4A100A3A182 /* Serialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3EF1EE2E4A100A3A182 /* Serialization.swift */; };
1639E3F01EE2E4A100A3A182 /* Encoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3EF1EE2E4A100A3A182 /* Encoder.swift */; };
1639E3F11EE2E4A100A3A182 /* Encoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3EF1EE2E4A100A3A182 /* Encoder.swift */; };
1639E3F31EE2EA1500A3A182 /* Serializable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3F21EE2EA1500A3A182 /* Serializable.swift */; };
1639E3F41EE2EA1500A3A182 /* Serializable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3F21EE2EA1500A3A182 /* Serializable.swift */; };
1639E3F61EE44DC900A3A182 /* KeyCommands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1639E3F51EE44DC900A3A182 /* KeyCommands.swift */; };
Expand All @@ -32,12 +31,13 @@
167A433D1E84540A00083790 /* Operations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 167A43241E8453A300083790 /* Operations.swift */; };
167A433E1E84540A00083790 /* Reducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 167A43251E8453A300083790 /* Reducer.swift */; };
167A433F1E84540A00083790 /* Store.swift in Sources */ = {isa = PBXBuildFile; fileRef = 167A43261E8453A300083790 /* Store.swift */; };
16C78B921F3C98A00054BC6E /* RecorderMiddleware.swift in Sources */ = {isa = PBXBuildFile; fileRef = 16C78B911F3C98A00054BC6E /* RecorderMiddleware.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
1601D4231E8895B6008A2CF5 /* Action.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Action.swift; sourceTree = "<group>"; };
1639E3E81EE2E27D00A3A182 /* PushID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PushID.swift; sourceTree = "<group>"; };
1639E3EF1EE2E4A100A3A182 /* Serialization.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Serialization.swift; path = deps/Serialization.swift; sourceTree = SOURCE_ROOT; };
1639E3EF1EE2E4A100A3A182 /* Encoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Encoder.swift; path = deps/Encoder.swift; sourceTree = SOURCE_ROOT; };
1639E3F21EE2EA1500A3A182 /* Serializable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Serializable.swift; sourceTree = "<group>"; };
1639E3F51EE44DC900A3A182 /* KeyCommands.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = KeyCommands.swift; path = deps/KeyCommands.swift; sourceTree = SOURCE_ROOT; };
167A43161E8452C900083790 /* DispatchStore_iOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DispatchStore_iOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -52,7 +52,7 @@
167A43321E8453E100083790 /* DispatchStore_macOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DispatchStore_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
167A43341E8453E100083790 /* Dispatcher_macOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Dispatcher_macOS.h; sourceTree = "<group>"; };
167A43351E8453E100083790 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
16D979D11E88C4CB00F4430B /* RecorderMiddleware.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecorderMiddleware.swift; sourceTree = "<group>"; };
16C78B911F3C98A00054BC6E /* RecorderMiddleware.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecorderMiddleware.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -76,7 +76,7 @@
1639E3EB1EE2E39500A3A182 /* deps */ = {
isa = PBXGroup;
children = (
1639E3EF1EE2E4A100A3A182 /* Serialization.swift */,
1639E3EF1EE2E4A100A3A182 /* Encoder.swift */,
1639E3F51EE44DC900A3A182 /* KeyCommands.swift */,
1639E3E81EE2E27D00A3A182 /* PushID.swift */,
);
Expand Down Expand Up @@ -140,7 +140,7 @@
isa = PBXGroup;
children = (
167A43221E8453A300083790 /* LoggerMiddleware.swift */,
16D979D11E88C4CB00F4430B /* RecorderMiddleware.swift */,
16C78B911F3C98A00054BC6E /* RecorderMiddleware.swift */,
);
name = middleware;
sourceTree = "<group>";
Expand Down Expand Up @@ -264,7 +264,7 @@
buildActionMask = 2147483647;
files = (
1639E3F61EE44DC900A3A182 /* KeyCommands.swift in Sources */,
1639E3F01EE2E4A100A3A182 /* Serialization.swift in Sources */,
1639E3F01EE2E4A100A3A182 /* Encoder.swift in Sources */,
1639E3E91EE2E27D00A3A182 /* PushID.swift in Sources */,
1639E3F31EE2EA1500A3A182 /* Serializable.swift in Sources */,
167A43291E8453A300083790 /* Middleware.swift in Sources */,
Expand All @@ -273,8 +273,8 @@
167A432C1E8453A300083790 /* Store.swift in Sources */,
1601D4241E8895B6008A2CF5 /* Action.swift in Sources */,
167A432B1E8453A300083790 /* Reducer.swift in Sources */,
16C78B921F3C98A00054BC6E /* RecorderMiddleware.swift in Sources */,
167A432A1E8453A300083790 /* Operations.swift in Sources */,
162B39C11EC08DBF0074E075 /* RecorderMiddleware.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -292,7 +292,7 @@
1601D4251E8895D3008A2CF5 /* Action.swift in Sources */,
167A433E1E84540A00083790 /* Reducer.swift in Sources */,
167A433D1E84540A00083790 /* Operations.swift in Sources */,
1639E3F11EE2E4A100A3A182 /* Serialization.swift in Sources */,
1639E3F11EE2E4A100A3A182 /* Encoder.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions src/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ public final class Dispatcher {

/// Returns the store with the given identifier.
public func store(with identifier: String) -> StoreType? {
return self.stores.filter { $0.identifier == identifier }.first
return stores.filter { $0.identifier == identifier }.first
}

public func register(store: StoreType) {
precondition(Thread.isMainThread)
self.stores.append(store)
stores.append(store)
}

public func unregister(identifier: String) {
precondition(Thread.isMainThread)
self.stores = self.stores.filter { $0.identifier == identifier }
stores = stores.filter { $0.identifier == identifier }
}

public func register(middleware: MiddlewareType) {
Expand All @@ -52,10 +52,10 @@ public final class Dispatcher {
then: ((Void) -> (Void))? = nil) {
var stores = self.stores
if let storeIdentifier = storeIdentifier {
stores = self.stores.filter { $0.identifier == storeIdentifier }
stores = stores.filter { $0.identifier == storeIdentifier }
}
for store in stores where store.responds(to: action) {
self.run(action: action, mode: mode, store: store, then: then)
run(action: action, mode: mode, store: store, then: then)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Operations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class ActionOperation<S: ModelType, A: ActionType>: AsynchronousOperation

public override func execute() {
guard let store = store else {
self.finish()
finish()
return
}
self.block(self, self.action, store)
}

override public func finish() {
self.finishBlock()
finishBlock()
super.finish()
}

Expand Down
25 changes: 12 additions & 13 deletions src/PushID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ public func makePushID() -> String {
return PushID.default.make()
}

/** ID generator that creates 20-character string identifiers with the following properties:
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with
* other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will
* sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp,
* the latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
/// ID generator that creates 20-character string identifiers with the following properties:
/// 1. They're based on timestamp so that they sort *after* any existing ids.
/// 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with
/// other clients' IDs.
/// 3. They sort *lexicographically* (so the timestamp is converted to characters that will
/// sort properly).
/// 4. They're monotonically increasing. Even if you generate more than one in the same timestamp,
/// the latter ones will sort after the former ones. We do this by using the previous random bits
/// but "incrementing" them by 1 (only in the case of a timestamp collision).
public class PushID {

// MARK: Static constants
Expand Down Expand Up @@ -103,8 +102,8 @@ public class PushID {
private var spin = OS_SPINLOCK_INIT
private var unfair = os_unfair_lock_s()

/** Locks a spinlock. Although the lock operation spins, it employs various strategies to back
* off if the lock is held. */
/// Locks a spinlock. Although the lock operation spins, it employs various strategies to back
/// off if the lock is held.
fileprivate func lock() {
if #available(iOS 10, *) {
os_unfair_lock_lock(&unfair)
Expand All @@ -113,7 +112,7 @@ public class PushID {
}
}

/** Unlocks a spinlock. */
/// Unlocks a spinlock.
fileprivate func unlock() {
if #available(iOS 10, *) {
os_unfair_lock_unlock(&unfair)
Expand Down
Loading

0 comments on commit 7bc5aeb

Please sign in to comment.