Skip to content

Commit 3c99c85

Browse files
Merge pull request #9 from NeedleInAJayStack/feature/documentation
Updates documentation & changes name to DataLoader
2 parents a264c85 + 3b8dd9e commit 3c99c85

12 files changed

+156
-148
lines changed

.gitignore

+34-16
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22
#
33
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
44

5-
## Build generated
5+
## User settings
6+
xcuserdata/
7+
8+
## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
9+
*.xcscmblueprint
10+
*.xccheckout
11+
12+
## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
613
build/
714
DerivedData/
8-
9-
## Various settings
15+
*.moved-aside
1016
*.pbxuser
1117
!default.pbxuser
1218
*.mode1v3
@@ -15,15 +21,11 @@ DerivedData/
1521
!default.mode2v3
1622
*.perspectivev3
1723
!default.perspectivev3
18-
xcuserdata/
19-
20-
## Other
21-
*.moved-aside
22-
*.xccheckout
23-
*.xcscmblueprint
2424

2525
## Obj-C/Swift specific
2626
*.hmap
27+
28+
## App packaging
2729
*.ipa
2830
*.dSYM.zip
2931
*.dSYM
@@ -38,11 +40,13 @@ playground.xcworkspace
3840
# Packages/
3941
# Package.pins
4042
# Package.resolved
41-
.DS_Store
42-
/.build
43-
/Packages
44-
/*.xcodeproj
43+
# *.xcodeproj
44+
#
45+
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
46+
# hence it is not needed unless you have added a package configuration file to your project
47+
.swiftpm
4548

49+
.build/
4650

4751
# CocoaPods
4852
#
@@ -51,22 +55,36 @@ playground.xcworkspace
5155
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
5256
#
5357
# Pods/
58+
#
59+
# Add this line if you want to avoid checking in source code from the Xcode workspace
60+
# *.xcworkspace
5461

5562
# Carthage
5663
#
5764
# Add this line if you want to avoid checking in source code from Carthage dependencies.
5865
# Carthage/Checkouts
5966

60-
Carthage/Build
67+
Carthage/Build/
68+
69+
# Accio dependency management
70+
Dependencies/
71+
.accio/
6172

6273
# fastlane
6374
#
64-
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
65-
# screenshots whenever they are needed.
75+
# It is recommended to not store the screenshots in the git repo.
76+
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
6677
# For more information about the recommended setup visit:
6778
# https://docs.fastlane.tools/best-practices/source-control/#source-control
6879

6980
fastlane/report.xml
7081
fastlane/Preview.html
7182
fastlane/screenshots/**/*.png
7283
fastlane/test_output
84+
85+
# Code Injection
86+
#
87+
# After new code Injection tools there's a generated folder /iOSInjectionProject
88+
# https://github.com/johnno1962/injectionforxcode
89+
90+
iOSInjectionProject/

Package.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import PackageDescription
55

66
let package = Package(
7-
name: "SwiftDataLoader",
7+
name: "DataLoader",
88
products: [
9-
.library(name: "SwiftDataLoader", targets: ["SwiftDataLoader"]),
9+
.library(name: "DataLoader", targets: ["DataLoader"]),
1010
],
1111
dependencies: [
1212
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
1313
],
1414
targets: [
15-
.target(name: "SwiftDataLoader", dependencies: ["NIO"]),
16-
.testTarget(name: "SwiftDataLoaderTests", dependencies: ["SwiftDataLoader"]),
15+
.target(name: "DataLoader", dependencies: ["NIO"]),
16+
.testTarget(name: "DataLoaderTests", dependencies: ["DataLoader"]),
1717
],
1818
swiftLanguageVersions: [.v5]
1919
)

README.md

+40-31
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# SwiftDataLoader
2-
SwiftDataLoader is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
1+
# DataLoader
2+
DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
33

44
This is a Swift version of the Facebook [DataLoader](https://github.com/facebook/dataloader).
55

6-
[![CircleCI](https://circleci.com/gh/kimdv/SwiftDataLoader.svg?style=svg)](https://circleci.com/gh/kimdv/SwiftDataLoader)
7-
[![codecov](https://codecov.io/gh/kimdv/SwiftDataLoader/branch/master/graph/badge.svg)](https://codecov.io/gh/kimdv/SwiftDataLoader)
6+
[![Swift][swift-badge]][swift-url]
7+
[![License][mit-badge]][mit-url]
88

99
## Installation 💻
1010

1111
Update your `Package.swift` file.
1212

1313
```swift
14-
.Package(url: "https://github.com/kimdv/SwiftDataLoader.git", majorVersion: 1)
14+
.Package(url: "https://github.com/GraphQLSwift/DataLoader.git", .upToNextMajor(from: "1.1.0"))
1515
```
1616

1717
## Gettings started 🚀
@@ -27,27 +27,27 @@ let userLoader = Dataloader<Int, User>(batchLoadFunction: { keys in
2727
})
2828
```
2929
#### Load single key
30-
```
31-
let future1 = try userLoader.load(key: 1, on: req)
32-
let future2 = try userLoader.load(key: 2, on: req)
33-
let future3 = try userLoader.load(key: 1, on: req)
30+
```swift
31+
let future1 = try userLoader.load(key: 1, on: eventLoopGroup)
32+
let future2 = try userLoader.load(key: 2, on: eventLoopGroup)
33+
let future3 = try userLoader.load(key: 1, on: eventLoopGroup)
3434
```
3535

3636
Now there is only one thing left and that is to dispathc it `try userLoader.dispatchQueue(on: req.eventLoop)`
3737

3838
The example above will only fetch two users, because the user with key `1` is present twice in the list.
3939

4040
#### Load multiple keys
41-
There is also an API to load multiple keys at once
42-
```
43-
try userLoader.loadMany(keys: [1, 2, 3], on: req.eventLoop)
41+
There is also a method to load multiple keys at once
42+
```swift
43+
try userLoader.loadMany(keys: [1, 2, 3], on: eventLoopGroup)
4444
```
4545

46-
### Disable batching
47-
It is also possible to disable batching `DataLoaderOptions(batchingEnabled: false)`
48-
It will invoke `batchLoadFunction` with a single key
46+
#### Disable batching
47+
It is possible to disable batching `DataLoaderOptions(batchingEnabled: false)`
48+
It will invoke `batchLoadFunction` immediately whenever any key is loaded
4949

50-
### Chaching
50+
### Caching
5151

5252
DataLoader provides a memoization cache for all loads which occur in a single
5353
request to your application. After `.load()` is called once with a given key,
@@ -58,8 +58,8 @@ also creates fewer objects which may relieve memory pressure on your application
5858

5959
```swift
6060
let userLoader = DataLoader<Int, Int>(...)
61-
let future1 = userLoader.load(1)
62-
let future2 = userLoader.load(1)
61+
let future1 = userLoader.load(key: 1, on: eventLoopGroup)
62+
let future2 = userLoader.load(key: 1, on: eventLoopGroup)
6363
assert(future1 === future2)
6464
```
6565

@@ -91,13 +91,13 @@ Here's a simple example using SQL UPDATE to illustrate.
9191
let userLoader = DataLoader<Int, Int>(...)
9292

9393
// And a value happens to be loaded (and cached).
94-
userLoader.load(4)
94+
userLoader.load(key: 4, on: eventLoopGroup)
9595

9696
// A mutation occurs, invalidating what might be in cache.
9797
sqlRun('UPDATE users WHERE id=4 SET username="zuck"').then { userLoader.clear(4) }
9898

9999
// Later the value load is loaded again so the mutated data appears.
100-
userLoader.load(4)
100+
userLoader.load(key: 4, on: eventLoopGroup)
101101

102102
// Request completes.
103103
```
@@ -112,19 +112,19 @@ be cached to avoid frequently loading the same `Error`.
112112
In some circumstances you may wish to clear the cache for these individual Errors:
113113

114114
```swift
115-
userLoader.load(1).catch { error in {
115+
userLoader.load(key: 1, on: eventLoopGroup).catch { error in {
116116
if (/* determine if should clear error */) {
117-
userLoader.clear(1);
118-
}
119-
throw error
117+
userLoader.clear(key: 1);
118+
}
119+
throw error
120120
}
121121
```
122122

123123
#### Disabling Cache
124124

125125
In certain uncommon cases, a DataLoader which *does not* cache may be desirable.
126126
Calling `DataLoader(options: DataLoaderOptions(cachingEnabled: false), batchLoadFunction: batchLoadFunction)` will ensure that every
127-
call to `.load()` will produce a *new* Future, and requested keys will not be
127+
call to `.load()` will produce a *new* Future, and previously requested keys will not be
128128
saved in memory.
129129

130130
However, when the memoization cache is disabled, your batch function will
@@ -135,13 +135,16 @@ for each instance of the requested key.
135135
For example:
136136

137137
```swift
138-
let myLoader = DataLoader<String, String>(options: DataLoaderOptions(cachingEnabled: false), batchLoadFunction: { keys in
139-
self.someBatchLoader(keys: keys).map { DataLoaderFutureValue.success($0) }
140-
})
138+
let myLoader = DataLoader<String, String>(
139+
options: DataLoaderOptions(cachingEnabled: false),
140+
batchLoadFunction: { keys in
141+
self.someBatchLoader(keys: keys).map { DataLoaderFutureValue.success($0) }
142+
}
143+
)
141144

142-
myLoader.load("A")
143-
myLoader.load("B")
144-
myLoader.load("A")
145+
myLoader.load(key: "A", on: eventLoopGroup)
146+
myLoader.load(key: "B", on: eventLoopGroup)
147+
myLoader.load(key: "A", on: eventLoopGroup)
145148

146149
// > [ "A", "B", "A" ]
147150
```
@@ -171,3 +174,9 @@ When creating a pull request, please adhere to the current coding style where po
171174

172175
This library is entirely a Swift version of Facebooks [DataLoader](https://github.com/facebook/dataloader). Developed by [Lee Byron](https://github.com/leebyron) and
173176
[Nicholas Schrock](https://github.com/schrockn) from [Facebook](https://www.facebook.com/).
177+
178+
[swift-badge]: https://img.shields.io/badge/Swift-5.2-orange.svg?style=flat
179+
[swift-url]: https://swift.org
180+
181+
[mit-badge]: https://img.shields.io/badge/License-MIT-blue.svg?style=flat
182+
[mit-url]: https://tldrlegal.com/license/mit-license

0 commit comments

Comments
 (0)