Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring the ModelChange API to use a real model instead of optionals #48

Merged
merged 8 commits into from
Dec 22, 2016

Conversation

plivesey
Copy link
Owner

This makes the API much easier to use and avoids double optionals

Peter Livesey added 7 commits December 16, 2016 11:36
This allows me to delete the new weak array code added here
Fixing a bug
Updating docs
Some style fixes
This makes the public API for this cleaner and avoids double optionals
@@ -316,10 +316,9 @@ open class ConsistencyManager {
open func updateModel(_ model: ConsistencyManagerModel, context: Any? = nil) {
dispatchTask { cancelled in
let tuple = self.childrenAndListenersForModel(model)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tuple is not a great variable name, so I would just unwrap it on the spot.

let (modelUpdates, listeners) = self.childrenAndListenersForModel(model)

@@ -356,7 +355,7 @@ open class ConsistencyManager {
}()

// A simple update dictionary. We're just deleting a model with this id. Nothing else.
let updatesDictionary: [String: [ConsistencyManagerModel]?] = [ id: nil ]
let updatesDictionary = [ id: ModelChange.deleted ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no space after/before [/]

let updatesDictionary = [id: ModelChange.deleted]

// It's an update. Let's apply the changes.
let mergedReplacementModel = mergedModelFromModel(model, withUpdates: replacementModel)
let mergedReplacementModel = mergedModelFromModel(model, withUpdates: replacementModels)
Copy link

@nicksnyder nicksnyder Dec 19, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withUpdates label seems out of date now. Should either match the type (e.g. withModelChanges) or just be with since it now has a strong type (my preference is the latter).

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

*/
public enum ModelChange: Equatable {
/**
This indicates that this ID has been updated with a new model.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is kind of weird to reference this ID in the documentation here, because this type knows nothing of the ID. Maybe it should?

Assuming the current implementation, I would recommend describing/documenting this type without any assumption about how it would be used.

If you want to document the [String: ModelChange] data structure used elsewhere, create a typealias (or a proper type) somewhere and document that.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some docs to the delegate method which people will probably read first and changed these.

return isEqual && tuple.0.isEqualToModel(tuple.1)
}
case (.deleted, .deleted):
return true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of weird that all deletes are considered equal. Maybe this data structure should capture the ID or the old model for deletes.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so you can do: if modelChanges[id] == .delete

I'm not sure it should capture the old ID. I think the problem here is that this captures the whole change. It doesn't, it only specifies that something has changed. For instance, updates don't capture the old model, only the new model.

@@ -12,12 +12,26 @@ import ConsistencyManager

class TestUpdatesListener: ConsistencyManagerUpdatesListener {

var updateClosure: ((ConsistencyManagerModel, [String : [ConsistencyManagerModel]?], Any?) -> Void)?
var updateClosure: ((ConsistencyManagerModel, [String : ModelChange], Any?) -> ())?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this back to -> (). I thought -> Void was preferred? (3.8.2)

@plivesey plivesey merged commit 0c6bf9a into master Dec 22, 2016
@plivesey plivesey deleted the deleteRefactor branch December 22, 2016 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants