Skip to content

Commit 788a84d

Browse files
author
Alex Usbergo
committed
style
1 parent f43b938 commit 788a84d

10 files changed

+469
-611
lines changed

Buffer.podspec

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# Be sure to run `pod lib lint Render.podspec' to ensure this is a
3+
# valid spec before submitting.
4+
#
5+
# Any lines starting with a # are optional, but their use is encouraged
6+
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
7+
#
8+
9+
Pod::Spec.new do |s|
10+
s.name = "Buffer"
11+
s.version = "2.1"
12+
s.summary = "Swift and UIKit a la React."
13+
14+
# This description is used to generate tags and improve search results.
15+
# * Think: What does it do? Why did you write it? What is the focus?
16+
# * Try to keep it short, snappy and to the point.
17+
# * Write the description between the DESC delimiters below.
18+
# * Finally, don't worry about the indent, CocoaPods strips it!
19+
20+
s.description = <<-DESC
21+
React-inspired swift library for writing UIKit UIs.
22+
DESC
23+
24+
s.homepage = "https://github.com/alexdrone/Render"
25+
s.screenshots = "https://github.com/alexdrone/Render/raw/master/Doc/logo.png"
26+
s.license = 'MIT'
27+
s.author = { "Alex Usbergo" => "[email protected]" }
28+
s.source = { :git => "https://github.com/alexdrone/Render.git", :tag => s.version.to_s }
29+
s.social_media_url = 'https://twitter.com/alexdrone'
30+
31+
s.ios.deployment_target = '8.0'
32+
33+
s.source_files = 'Render/**/*'
34+
35+
# s.resource_bundles = {
36+
# 'Render' => ['Render/Assets/*.png']
37+
# }
38+
39+
# s.public_header_files = 'Pod/Classes/**/*.h'
40+
# s.frameworks = 'UIKit', 'MapKit'
41+
# s.dependency 'AFNetworking', '~> 2.3'
42+
end

Buffer/AdapterType.swift

+10-35
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,28 @@
1-
//
2-
// AdapterType.swift
3-
// Buffer
4-
//
5-
// Copyright (c) 2016 Alex Usbergo.
6-
//
7-
// Permission is hereby granted, free of charge, to any person obtaining a copy
8-
// of this software and associated documentation files (the "Software"), to deal
9-
// in the Software without restriction, including without limitation the rights
10-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
// copies of the Software, and to permit persons to whom the Software is
12-
// furnished to do so, subject to the following conditions:
13-
//
14-
// The above copyright notice and this permission notice shall be included in
15-
// all copies or substantial portions of the Software.
16-
//
17-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23-
// THE SOFTWARE.
24-
//
25-
26-
271
import Foundation
282

293
public protocol AdapterType {
304

315
associatedtype `Type`
326
associatedtype ViewType
337

34-
///Returns the element currently on the front buffer at the given index path.
8+
/** Returns the element currently on the front buffer at the given index path. */
359
func displayedElement(at index: Int) -> Type
3610

37-
///The total number of elements currently displayed.
11+
/** The total number of elements currently displayed. */
3812
func countDisplayedElements() -> Int
3913

40-
///Replace the elements buffer and compute the diffs.
41-
/// - parameter newValues: The new values.
42-
/// - parameter synchronous: Wether the filter, sorting and diff should be executed
43-
/// synchronously or not.
44-
/// - parameter completion: Code that will be executed once the buffer is updated.
14+
/** Replace the elements buffer and compute the diffs.
15+
* - parameter newValues: The new values.
16+
* - parameter synchronous: Wether the filter, sorting and diff should be executed
17+
* synchronously or not.
18+
* - parameter completion: Code that will be executed once the buffer is updated.
19+
*/
4520
func update(with values: [Type]?, synchronous: Bool, completion: ((Void) -> Void)?)
4621

47-
///The section index associated with this adapter.
22+
/** The section index associated with this adapter. */
4823
var sectionIndex: Int { get set }
4924

50-
///The target view.
25+
/** The target view. */
5126
var view: ViewType? { get }
5227

5328
init(buffer: BufferType, view: ViewType)

Buffer/AnyListItem.swift

+4-29
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
//
2-
// AnyListItemType.swift
3-
// BufferDiff
4-
//
5-
// Copyright (c) 2016 Alex Usbergo.
6-
//
7-
// Permission is hereby granted, free of charge, to any person obtaining a copy
8-
// of this software and associated documentation files (the "Software"), to deal
9-
// in the Software without restriction, including without limitation the rights
10-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
// copies of the Software, and to permit persons to whom the Software is
12-
// furnished to do so, subject to the following conditions:
13-
//
14-
// The above copyright notice and this permission notice shall be included in
15-
// all copies or substantial portions of the Software.
16-
//
17-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23-
// THE SOFTWARE.
24-
//
25-
261
import Foundation
272

283
public protocol ListContainerView: class { }
@@ -42,13 +17,13 @@ public func ==<Type>(lhs: AnyListItem<Type>, rhs: AnyListItem<Type>) -> Bool {
4217

4318
public struct AnyListItem<Type: Equatable>: Equatable {
4419

45-
///The reuse identifier for the cell passed as argument.
20+
/** The reuse identifier for the cell passed as argument. */
4621
public var reuseIdentifier: String
4722

48-
///The actual item data.
23+
/** The actual item data. */
4924
public var state: Type
5025

51-
///The TableView, or the CollectionView that will own this element.
26+
/** The TableView, or the CollectionView that will own this element. */
5227
public let referenceView: ListContainerView?
5328

5429
public var cellConfiguration: ((ListViewCell, Type) -> Void)?
@@ -61,7 +36,7 @@ public struct AnyListItem<Type: Equatable>: Equatable {
6136
state: Type,
6237
configurationClosure: ((ListViewCell, Type) -> Void)? = nil) {
6338

64-
//registers the prototype cell if necessary.
39+
// registers the prototype cell if necessary.
6540
if !Prototypes.isPrototypeCellRegistered(reuseIdentifer) {
6641
let cell = V(reuseIdentifier: reuseIdentifer)
6742
Prototypes.registerPrototypeCell(reuseIdentifer, cell: cell)

Buffer/Buffer.swift

+31-56
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,51 @@
1-
2-
//
3-
// Buffer.swift
4-
// Buffer
5-
//
6-
// Created by Alex Usbergo on 02/05/16.
7-
//
8-
// Copyright (c) 2016 Alex Usbergo.
9-
//
10-
// Permission is hereby granted, free of charge, to any person obtaining a copy
11-
// of this software and associated documentation files (the "Software"), to deal
12-
// in the Software without restriction, including without limitation the rights
13-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14-
// copies of the Software, and to permit persons to whom the Software is
15-
// furnished to do so, subject to the following conditions:
16-
//
17-
// The above copyright notice and this permission notice shall be included in
18-
// all copies or substantial portions of the Software.
19-
//
20-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26-
// THE SOFTWARE.
27-
//
28-
291
import Foundation
302

313
public protocol BufferType { }
324

335
public protocol BufferDelegate: class {
346

35-
/// Notifies the receiver that the content is about to change
7+
/** Notifies the receiver that the content is about to change */
368
func buffer(willChangeContent buffer: BufferType)
379

38-
/// Notifies the receiver that rows were deleted.
10+
/** Notifies the receiver that rows were deleted. */
3911
func buffer(didDeleteElementAtIndices buffer: BufferType, indices: [UInt])
4012

41-
/// Notifies the receiver that rows were inserted.
13+
/** Notifies the receiver that rows were inserted. */
4214
func buffer(didInsertElementsAtIndices buffer: BufferType, indices: [UInt])
4315

44-
/// Notifies the receiver that the content updates has ended.
16+
/** Notifies the receiver that the content updates has ended. */
4517
func buffer(didChangeContent buffer: BufferType)
4618

47-
/// Notifies the receiver that the content updates has ended.
48-
/// This callback method is called when the number of changes are too many to be
49-
/// handled for the UI thread - it's recommendable to just reload the whole data in this case.
50-
/// - Note: The 'diffThreshold' property in 'Buffer' defines what is the maximum number
51-
/// of changes
52-
/// that you want the receiver to be notified for.
19+
/** Notifies the receiver that the content updates has ended.
20+
* This callback method is called when the number of changes are too many to be
21+
* handled for the UI thread - it's recommendable to just reload the whole data in this case.
22+
* - Note: The 'diffThreshold' property in 'Buffer' defines what is the maximum number
23+
* of changes
24+
* that you want the receiver to be notified for.
25+
*/
5326
func buffer(didChangeAllContent buffer: BufferType)
5427

55-
/// Called when one of the observed properties for this object changed
28+
/** Called when one of the observed properties for this object changed. */
5629
func buffer(didChangeElementAtIndex buffer: BufferType, index: UInt)
5730
}
5831

5932
public class Buffer<ElementType: Equatable>: NSObject, BufferType {
6033

61-
/// The object that will get notified every time changes occures to the array.
34+
/** The object that will get notified every time changes occures to the array. */
6235
public weak var delegate: BufferDelegate?
6336

64-
/// The elements in the array observer's buffer.
37+
/** The elements in the array observer's buffer. */
6538
public var currentElements: [ElementType] {
6639
return self.frontBuffer
6740
}
6841

69-
/// Defines what is the maximum number of changes that you want the receiver to be notified for.
42+
/** Defines what is the maximum number of changes that you want the receiver to be notified for. */
7043
public var diffThreshold = 50
7144

72-
/// If set to 'true' the LCS algorithm is run synchronously on the main thread.
45+
// If set to 'true' the LCS algorithm is run synchronously on the main thread.
7346
fileprivate var synchronous: Bool = false
7447

75-
/// The two buffers.
48+
// The two buffers.
7649
fileprivate var frontBuffer = [ElementType]() {
7750
willSet {
7851
assert(Thread.isMainThread)
@@ -85,13 +58,13 @@ public class Buffer<ElementType: Equatable>: NSObject, BufferType {
8558
}
8659
fileprivate var backBuffer = [ElementType]()
8760

88-
/// Sort closure.
61+
// Sort closure.
8962
fileprivate var sort: ((ElementType, ElementType) -> Bool)?
9063

91-
/// Filter closure.
64+
// Filter closure.
9265
fileprivate var filter: ((ElementType) -> Bool)?
9366

94-
/// The serial operation queue for this controller.
67+
// The serial operation queue for this controller.
9568
fileprivate let serialOperationQueue: OperationQueue = {
9669
let operationQueue = OperationQueue()
9770
operationQueue.maxConcurrentOperationCount = 1
@@ -101,7 +74,7 @@ public class Buffer<ElementType: Equatable>: NSObject, BufferType {
10174
fileprivate var flags = (isRefreshing: false,
10275
shouldRefresh: false)
10376

104-
/// Used if 'Element' is KVO-compliant.
77+
// Used if 'Element' is KVO-compliant.
10578
fileprivate var trackedKeyPaths = [String]()
10679

10780
public init(initialArray: [ElementType],
@@ -117,7 +90,7 @@ public class Buffer<ElementType: Equatable>: NSObject, BufferType {
11790
self.observe(shouldObserveTrackedKeyPaths: false)
11891
}
11992

120-
/// Compute the diffs between the current array and the new one passed as argument.
93+
/** Compute the diffs between the current array and the new one passed as argument. */
12194
public func update(
12295
with values: [ElementType]? = nil,
12396
synchronous: Bool = false,
@@ -182,8 +155,9 @@ public class Buffer<ElementType: Equatable>: NSObject, BufferType {
182155
}
183156
}
184157

185-
/// This message is sent to the receiver when the value at the specified key path relative
186-
/// to the given object has changed.
158+
/** This message is sent to the receiver when the value at the specified key path relative
159+
* to the given object has changed.
160+
*/
187161
public override func observeValue(forKeyPath keyPath: String?,
188162
of object: Any?,
189163
change: [NSKeyValueChangeKey : Any]?,
@@ -200,11 +174,11 @@ public class Buffer<ElementType: Equatable>: NSObject, BufferType {
200174
}
201175
}
202176

203-
//MARK: KVO Extension
177+
// MARK: KVO Extension
204178

205179
extension Buffer where ElementType: AnyObject {
206180

207-
///Observe the keypaths passed as argument.
181+
/** Observe the keypaths passed as argument. */
208182
public func trackKeyPaths(_ keypaths: [String]) {
209183
self.observe(shouldObserveTrackedKeyPaths: false)
210184
self.trackedKeyPaths = keypaths
@@ -214,8 +188,9 @@ extension Buffer where ElementType: AnyObject {
214188

215189
extension Buffer {
216190

217-
/// Adds or remove observations.
218-
/// - Note: This code is executed only when 'Element: AnyObject'.
191+
/** Adds or remove observations.
192+
* - Note: This code is executed only when 'Element: AnyObject'.
193+
*/
219194
fileprivate func observe(shouldObserveTrackedKeyPaths: Bool = true) {
220195
if self.trackedKeyPaths.count == 0 {
221196
return
@@ -237,7 +212,7 @@ extension Buffer {
237212
}
238213
}
239214

240-
/// - Note: This code is executed only when 'Element: AnyObject'.
215+
// - Note: This code is executed only when 'Element: AnyObject'.
241216
fileprivate func objectDidChangeValue(for keyPath: String?, in object: AnyObject?) {
242217
dispatchOnMainThread {
243218
self.update() {

0 commit comments

Comments
 (0)