Skip to content

Commit

Permalink
version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnEstropia committed Oct 23, 2019
1 parent 48c2604 commit 1ad4b60
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 27 deletions.
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "JohnEstropia/CoreStore" "datasources"
github "JohnEstropia/CoreStore" >= 7.0.0
github "ReactiveX/RxSwift" >= 5.0.0
2 changes: 1 addition & 1 deletion Carthage/Checkouts/CoreStore
Submodule CoreStore updated 112 files
2 changes: 1 addition & 1 deletion Carthage/Checkouts/RxSwift
Submodule RxSwift updated 122 files
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ let package = Package(
dependencies: [
.Package(
url: "https://github.com/JohnEstropia/CoreStore.git",
"5.3.0"
"7.0.0"
),
.Package(
url: "https://github.com/ReactiveX/RxSwift.git",
"4.1.0"
"5.0.0"
)
],
exclude: ["Carthage", "RxCoreStoreDemo", "Sources/libA/images"]
Expand Down
2 changes: 1 addition & 1 deletion RxCoreStore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Pod::Spec.new do |s|
s.public_header_files = "Sources/**/*.h"
s.frameworks = "Foundation", "CoreData"
s.requires_arc = true
s.dependency "CoreStore", ">=6.0"
s.dependency "CoreStore", ">=7.0"
s.dependency "RxCocoa", ">=5.0"
s.dependency "RxSwift", ">=5.0"
end
12 changes: 12 additions & 0 deletions RxCoreStore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
B59D0DB22360061E001FB9D0 /* RxObjectPublisher+DataSources.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59D0DB12360061E001FB9D0 /* RxObjectPublisher+DataSources.swift */; };
B5A992111EA59F2B0091A2E3 /* RxCoreStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A992101EA59F2B0091A2E3 /* RxCoreStore.swift */; };
B5A992131EA5A0D90091A2E3 /* RxDataStack+Setup.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A992121EA5A0D90091A2E3 /* RxDataStack+Setup.swift */; };
B5A992191EA74DD60091A2E3 /* RxDataStack+Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A992181EA74DD50091A2E3 /* RxDataStack+Transaction.swift */; };
Expand All @@ -21,6 +22,7 @@
B5D3399F1E9226FB00C880DE /* RxBlocking.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5D3399E1E9226FB00C880DE /* RxBlocking.framework */; };
B5E377701EE685CE00434A93 /* RxObjectMonitor+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E3776F1EE685CE00434A93 /* RxObjectMonitor+Observing.swift */; };
B5E377721EE68B1B00434A93 /* RxDynamicObject+Observing.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E377711EE68B1B00434A93 /* RxDynamicObject+Observing.swift */; };
B5FE58332359534B005F4991 /* RxListPublisher+DataSources.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5FE58322359534A005F4991 /* RxListPublisher+DataSources.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -34,6 +36,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
B59D0DB12360061E001FB9D0 /* RxObjectPublisher+DataSources.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RxObjectPublisher+DataSources.swift"; sourceTree = "<group>"; };
B5A992101EA59F2B0091A2E3 /* RxCoreStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RxCoreStore.swift; sourceTree = "<group>"; };
B5A992121EA5A0D90091A2E3 /* RxDataStack+Setup.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RxDataStack+Setup.swift"; sourceTree = "<group>"; };
B5A992181EA74DD50091A2E3 /* RxDataStack+Transaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RxDataStack+Transaction.swift"; sourceTree = "<group>"; };
Expand All @@ -57,6 +60,7 @@
B5D339AA1E92373600C880DE /* .travis.yml */ = {isa = PBXFileReference; lastKnownFileType = text; path = .travis.yml; sourceTree = SOURCE_ROOT; };
B5E3776F1EE685CE00434A93 /* RxObjectMonitor+Observing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RxObjectMonitor+Observing.swift"; sourceTree = "<group>"; };
B5E377711EE68B1B00434A93 /* RxDynamicObject+Observing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RxDynamicObject+Observing.swift"; sourceTree = "<group>"; };
B5FE58322359534A005F4991 /* RxListPublisher+DataSources.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RxListPublisher+DataSources.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -125,6 +129,8 @@
B5A992181EA74DD50091A2E3 /* RxDataStack+Transaction.swift */,
B5A9921A1EA74EAE0091A2E3 /* RxDataStack+Observing.swift */,
B5A9921C1EA74F770091A2E3 /* RxListMonitor+Observing.swift */,
B5FE58322359534A005F4991 /* RxListPublisher+DataSources.swift */,
B59D0DB12360061E001FB9D0 /* RxObjectPublisher+DataSources.swift */,
B5E377711EE68B1B00434A93 /* RxDynamicObject+Observing.swift */,
B5E3776F1EE685CE00434A93 /* RxObjectMonitor+Observing.swift */,
);
Expand Down Expand Up @@ -266,7 +272,9 @@
B5A992131EA5A0D90091A2E3 /* RxDataStack+Setup.swift in Sources */,
B5E377701EE685CE00434A93 /* RxObjectMonitor+Observing.swift in Sources */,
B5E377721EE68B1B00434A93 /* RxDynamicObject+Observing.swift in Sources */,
B5FE58332359534B005F4991 /* RxListPublisher+DataSources.swift in Sources */,
B5A992111EA59F2B0091A2E3 /* RxCoreStore.swift in Sources */,
B59D0DB22360061E001FB9D0 /* RxObjectPublisher+DataSources.swift in Sources */,
B5A9921B1EA74EAE0091A2E3 /* RxDataStack+Observing.swift in Sources */,
B5A9921D1EA74F770091A2E3 /* RxListMonitor+Observing.swift in Sources */,
B5A992191EA74DD60091A2E3 /* RxDataStack+Transaction.swift in Sources */,
Expand Down Expand Up @@ -418,13 +426,15 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 4;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.johnestropia.RxCoreStore;
PRODUCT_NAME = RxCoreStore;
SKIP_INSTALL = YES;
Expand All @@ -438,13 +448,15 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CURRENT_PROJECT_VERSION = 4;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 3;
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = Sources/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 2.0.0;
PRODUCT_BUNDLE_IDENTIFIER = com.johnestropia.RxCoreStore;
PRODUCT_NAME = RxCoreStore;
SKIP_INSTALL = YES;
Expand Down
31 changes: 23 additions & 8 deletions RxCoreStoreTests/RxCoreStoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class RxCoreStoreTests: XCTestCase {

func testExample() {

Shared.defaultStack = DataStack(
CoreStoreDefaults.dataStack = DataStack(
CoreStoreSchema(
modelVersion: "V1",
entities: [
Expand All @@ -70,7 +70,7 @@ class RxCoreStoreTests: XCTestCase {
)
)
let setupExpectation = self.expectation(description: "setup")
Shared.defaultStack.rx
CoreStoreDefaults.dataStack.rx
.addStorage(
SQLiteStore(
fileURL: SQLiteStore.defaultRootDirectory
Expand All @@ -92,8 +92,8 @@ class RxCoreStoreTests: XCTestCase {
)
.disposed(by: self.disposeBag)

let changeExpectation = self.expectation(description: "change")
let monitor = Shared.defaultStack.rx.monitorList(
let monitorChangeExpectation = self.expectation(description: "monitorChange")
let monitor = CoreStoreDefaults.dataStack.rx.monitorList(
From<Dog>()
.orderBy(.ascending(\.nickname))
)
Expand All @@ -105,17 +105,32 @@ class RxCoreStoreTests: XCTestCase {

case (let monitor, .listDidChange):
XCTAssertEqual(monitor.numberOfObjects(), 1)
changeExpectation.fulfill()
monitorChangeExpectation.fulfill()

default:
break
}
}
)
.disposed(by: self.disposeBag)

let publisherChangeExpectation = self.expectation(description: "publisherChange")
let publisher = CoreStoreDefaults.dataStack.listPublisher(
From<Dog>()
.orderBy(.ascending(\.nickname))
)
publisher.rx.snapshotSignal()
.emit(
onNext: { (snapshot) in

XCTAssertEqual(snapshot.numberOfItems, 1)
publisherChangeExpectation.fulfill()
}
)
.disposed(by: self.disposeBag)

let transactionExpectation = self.expectation(description: "transaction")
Shared.defaultStack.rx
CoreStoreDefaults.dataStack.rx
.perform(
asynchronous: { (transaction) -> Person in

Expand Down Expand Up @@ -151,7 +166,7 @@ class RxCoreStoreTests: XCTestCase {
.subscribe(
onSuccess: { (person) in

let validPerson = Shared.defaultStack.fetchExisting(person)
let validPerson = CoreStoreDefaults.dataStack.fetchExisting(person)
XCTAssertNotNil(validPerson)
XCTAssertNotNil(validPerson?.pet.value)

Expand All @@ -165,7 +180,7 @@ class RxCoreStoreTests: XCTestCase {
.disposed(by: self.disposeBag)

let importExpectation = self.expectation(description: "import")
Shared.defaultStack.rx
CoreStoreDefaults.dataStack.rx
.importUniqueObjects(
Into<Person>(),
sourceArray: [
Expand Down
4 changes: 2 additions & 2 deletions Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.4.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>3</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
16 changes: 8 additions & 8 deletions Sources/RxCoreStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ extension CoreStore {
*/
public static var rx: Reactive<DataStack> {

get { return Shared.defaultStack.rx }
set { Shared.defaultStack.rx = newValue }
get { return CoreStoreDefaults.dataStack.rx }
set { CoreStoreDefaults.dataStack.rx = newValue }
}
}

Expand Down Expand Up @@ -73,23 +73,23 @@ extension ObjectMonitor: ReactiveCompatible {
}


// MARK: - LiveList
// MARK: - ListPublisher

extension LiveList: ReactiveCompatible {
extension ListPublisher: ReactiveCompatible {

// MARK: ReactiveCompatible

public typealias ReactiveBase = LiveList
public typealias ReactiveBase = ListPublisher
}


// MARK: - LiveObject
// MARK: - ObjectPublisher

extension LiveObject: ReactiveCompatible {
extension ObjectPublisher: ReactiveCompatible {

// MARK: ReactiveCompatible

public typealias ReactiveBase = LiveObject
public typealias ReactiveBase = ObjectPublisher
}


Expand Down
6 changes: 3 additions & 3 deletions Sources/RxListMonitor+Observing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ extension ListMonitor: ObservableConvertibleType {

// MARK: ObservableConvertibleType

public typealias E = RxListChange<D>
public typealias E = RxListChange<O>

public func asObservable() -> Observable<RxListChange<D>> {
public func asObservable() -> Observable<RxListChange<O>> {

return Observable<RxListChange<D>>
return Observable<RxListChange<O>>
.create(
{ (observable) in

Expand Down
90 changes: 90 additions & 0 deletions Sources/RxListPublisher+DataSources.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// RxListPublisher+DataSources.swift
// RxCoreStore
//
// Copyright © 2017 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//

import CoreStore
import RxCocoa
import RxSwift


// MARK: - RxListPublisher

public protocol RxListPublisher {

associatedtype ObjectType: DynamicObject

var snapshot: ListSnapshot<ObjectType> { get }

func addObserver<T: AnyObject>(_ observer: T, _ callback: @escaping (ListPublisher<ObjectType>) -> Void)
func removeObserver<T: AnyObject>(_ observer: T)
}

extension ListPublisher: RxListPublisher {}


// MARK: - Reactive

extension Reactive where Base: RxListPublisher {

public func snapshotDriver() -> Driver<ListSnapshot<Base.ObjectType>> {

return Observable<ListSnapshot<Base.ObjectType>>
.create(
{ observer in

let token = NSObject()
self.base.addObserver(token) { (listPublisher) in

observer.onNext(listPublisher.snapshot)
}
return Disposables.create {

self.base.removeObserver(token)
}
}
)
.startWith(self.base.snapshot)
.asDriver(onErrorDriveWith: .never())
}

public func snapshotSignal() -> Signal<ListSnapshot<Base.ObjectType>> {

return Observable<ListSnapshot<Base.ObjectType>>
.create(
{ observer in

let token = NSObject()
self.base.addObserver(token) { (listPublisher) in

observer.onNext(listPublisher.snapshot)
}
return Disposables.create {

self.base.removeObserver(token)
}
}
)
.asSignal(onErrorSignalWith: .never())
}
}
Loading

0 comments on commit 1ad4b60

Please sign in to comment.