{"action":"created","issue":{"url":"https://api.github.com/repos/hyperoslo/Spots/issues/103","labels_url":"https://api.github.com/repos/hyperoslo/Spots/issues/103/labels{/name}","comments_url":"https://api.github.com/repos/hyperoslo/Spots/issues/103/comments","events_url":"https://api.github.com/repos/hyperoslo/Spots/issues/103/events","html_url":"https://github.com/hyperoslo/Spots/pull/103","id":123231676,"number":103,"title":"Improve public API","user":{"login":"zenangst","id":57446,"avatar_url":"https://avatars.githubusercontent.com/u/57446?v=3","gravatar_id":"","url":"https://api.github.com/users/zenangst","html_url":"https://github.com/zenangst","followers_url":"https://api.github.com/users/zenangst/followers","following_url":"https://api.github.com/users/zenangst/following{/other_user}","gists_url":"https://api.github.com/users/zenangst/gists{/gist_id}","starred_url":"https://api.github.com/users/zenangst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zenangst/subscriptions","organizations_url":"https://api.github.com/users/zenangst/orgs","repos_url":"https://api.github.com/users/zenangst/repos","events_url":"https://api.github.com/users/zenangst/events{/privacy}","received_events_url":"https://api.github.com/users/zenangst/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-12-21T08:38:11Z","updated_at":"2015-12-21T11:28:42Z","closed_at":"2015-12-21T11:28:26Z","pull_request":{"url":"https://api.github.com/repos/hyperoslo/Spots/pulls/103","html_url":"https://github.com/hyperoslo/Spots/pull/103","diff_url":"https://github.com/hyperoslo/Spots/pull/103.diff","patch_url":"https://github.com/hyperoslo/Spots/pull/103.patch"},"body":"This PR is an attempt to simplify the public API.\r\n\r\nIf you intend to create a `SpotsController` with only one `spot`, you know have some convenience methods to access the internal components. \r\n\r\n### SpotsController\r\n\r\n`SpotsController` has gained a convenience for initialising it with only one spot. This saves you from initialising a `SpotsController` with an array when you only intend to use it with one spot.\r\n\r\n### convenience init\r\n\r\n```swift\r\n   public convenience init(spot: Spotable)  {\r\n    self.init(spots: [spot])\r\n  }\r\n```\r\n\r\n`updateSpotAtIndex` is now called `update`. The first label `index` is optional because it defaults to `0`.\r\n\r\n```swift\r\npublic func update(spotAtIndex index: Int = 0, closure: (spot: Spotable) -> Spotable, completion: (() -> Void)? = nil) {\r\n```\r\n\r\nSo if you intend to use it with only one `spot` you can just drop `spotAtIndex` and only supply the update closure.\r\n\r\n```swift\r\n      self?.update(closure: { (spot) -> Spotable in\r\n        spot.component.items = items\r\n        return spot\r\n      })\r\n```\r\n\r\n### spot\r\n\r\n`SpotsController` now has a new computed variable that will return the first `spot`.\r\n\r\n```swift\r\n  public var spot: Spotable {\r\n    get {\r\n      return spot(0)!\r\n    }\r\n  }\r\n```\r\n\r\nNot a real big fan of having this force unwrapping but you could pretty much assume that you have at least one `spot`, hence me not seeing this a huge issue. Could probably be improved in the future.\r\n\r\nSo when you need access to the `spot` you just call it directly on the `SpotsController`.\r\n\r\n### Example\r\n\r\n#### Old implementation\r\n```diff\r\n-    if let componentItems = spotController?.spotAtIndex(0)?.component.items {\r\n-      XCTAssert(componentItems == items)\r\n-    }\r\n```\r\n#### New implementation\r\n```diff\r\n+    XCTAssert(spotController.spot.component.items == items)\r\n```\r\n\r\n### spotAtIndex\r\n`spotAtIndex` is replaced by a new method that is called `spot` that takes an index has its first argument. So if you plan to migrate a `SpotsController` from being a singular instance to a plural instance. Then the migration should be quiet easy, you just update the code base to include an index and use the function instead of the computed variable `spot`.\r\nYou could of course always access the computed variable even if you have more than one spot.\r\n\r\n`container` has been renamed to `spotsScrollView` to fit the rest of the naming convention that we have in `Spots`.\r\n\r\n### reloadSpots\r\n`reloadSpots` is renamed to `reload`.\r\n\r\n### Other improvements\r\n\r\n- [x] Remove `TitleSpot` type alias.\r\n- [x] The implementation now favours `forEach` over `for-in` to comply to the code styles.\r\n- [x] Refactor tests to not have optionals when calling the `spotsController`\r\n- [x] Simplify the demos to leverage from the new API changes"},"comment":{"url":"https://api.github.com/repos/hyperoslo/Spots/issues/comments/166277585","html_url":"https://github.com/hyperoslo/Spots/pull/103#issuecomment-166277585","issue_url":"https://api.github.com/repos/hyperoslo/Spots/issues/103","id":166277585,"user":{"login":"vadymmarkov","id":10529867,"avatar_url":"https://avatars.githubusercontent.com/u/10529867?v=3","gravatar_id":"","url":"https://api.github.com/users/vadymmarkov","html_url":"https://github.com/vadymmarkov","followers_url":"https://api.github.com/users/vadymmarkov/followers","following_url":"https://api.github.com/users/vadymmarkov/following{/other_user}","gists_url":"https://api.github.com/users/vadymmarkov/gists{/gist_id}","starred_url":"https://api.github.com/users/vadymmarkov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vadymmarkov/subscriptions","organizations_url":"https://api.github.com/users/vadymmarkov/orgs","repos_url":"https://api.github.com/users/vadymmarkov/repos","events_url":"https://api.github.com/users/vadymmarkov/events{/privacy}","received_events_url":"https://api.github.com/users/vadymmarkov/received_events","type":"User","site_admin":false},"created_at":"2015-12-21T11:28:42Z","updated_at":"2015-12-21T11:28:42Z","body":"@zenangst :star: "}}