zettajs / ZettaKit

The Zetta iOS Client Library.
MIT License
3 stars 2 forks source link

ZIKServer.devices links and transitions not populated #23

Closed benpackard closed 8 years ago

benpackard commented 8 years ago

Staring with the following serverSignal:

let rootSignal = ZIKSession.sharedSession().root(someNSURL)
let serverSignal = ZIKSession.sharedSession().servers(rootSignal)

I've noticed there are a couple of different ways to retrieve the devices from that API:

A. You can ask each server directly for its devices:

serverSignal.collect().subscribeNext { (servers) -> Void in
    guard let servers = servers as? [ZIKServer] else { return }
    for server in servers {
        guard let devices = server.devices as? [ZIKDevice] else { continue }
        print(devices.flatMap({ $0.name }))
    }
}
// ["apigee-pusher", "~system", "Display Screen", "Hue Hub", "Hue Bulb Carl", "Hue Bulb Zetta Demo", "Hue Bulb Hue Lamp 3", "Hue Bulb Hue Lamp 4", "Hue Bulb Hue Lamp 5", "Hue Bulb Hue Lamp 6"]

B. You can collect the devices directly from the devices signal:

let devicesSignal = ZIKSession.sharedSession().devices(serverSignal)
devicesSignal.collect().subscribeNext({ (devices) -> Void in
    if let devices = devices as? [ZIKDevice] {
        print(devices.flatMap({ $0.name }))
    }
})
// ["apigee-pusher", "~system", "Display Screen", "Hue Hub", "Hue Bulb Carl", "Hue Bulb Hue Lamp 3", "Hue Bulb Zetta Demo", "Hue Bulb Hue Lamp 4", "Hue Bulb Hue Lamp 5", "Hue Bulb Hue Lamp 6"]

On the face of it these are identical collections of ZIKDevices, though of course they are aggregated into a single array in method B. But on further inspection, only the devices in the second approach have their links and transitions populated.

I was just wondering if this is intentional, and what the difference/intended use of each approach is. As a rule, should I be using the second approach? Or are both valid?

mdobson commented 8 years ago

For full representations of devices you'll want method number 2. Either method could be valid depending on the use case.

The documentation on this needs some more improvement. Here is the gist:

  1. Each server has embedded representations of devices on their representation.
    1. This includes a self link, rel, properties.
    2. These devices are populated on a ZIKServer because they have a clear relationship between each other.
  2. Underneath the covers the devices signal takes these representations and fetches the full representations for each of the devices attached.

-Matt

-- Matthew Dobson | apigee https://apigee.com/ | m: +1.734.634.5472 | twitter @mdobs http://twitter.com/mdobs @apigee https://twitter.com/apigee | Apigee Community http://community.apigee.com/ for answers, ideas and support!

On Thu, Mar 3, 2016 at 4:09 PM, Ben Packard notifications@github.com wrote:

Staring with the following serverSignal:

let rootSignal = ZIKSession.sharedSession().root(someNSURL) let serverSignal = ZIKSession.sharedSession().servers(rootSignal)

I've noticed there are a couple of different ways to retrieve the devices from that API:

A. You can ask each server directly for its devices:

serverSignal.collect().subscribeNext { (servers) -> Void in guard let servers = servers as? [ZIKServer] else { return } for server in servers { guard let devices = server.devices as? [ZIKDevice] else { continue } print(devices.flatMap({ $0.name })) } } // ["apigee-pusher", "~system", "Display Screen", "Hue Hub", "Hue Bulb Carl", "Hue Bulb Zetta Demo", "Hue Bulb Hue Lamp 3", "Hue Bulb Hue Lamp 4", "Hue Bulb Hue Lamp 5", "Hue Bulb Hue Lamp 6"]

B. You can collect the devices directly from the devices signal:

let devicesSignal = ZIKSession.sharedSession().devices(serverSignal) devicesSignal.collect().subscribeNext({ (devices) -> Void in if let devices = devices as? [ZIKDevice] { print(devices.flatMap({ $0.name })) } }) // ["apigee-pusher", "~system", "Display Screen", "Hue Hub", "Hue Bulb Carl", "Hue Bulb Hue Lamp 3", "Hue Bulb Zetta Demo", "Hue Bulb Hue Lamp 4", "Hue Bulb Hue Lamp 5", "Hue Bulb Hue Lamp 6"]

On the face of it these are identical collections of ZIKDevices, though of course they are aggregated into a single array in method B. But on further inspection, only the devices in the second approach have their links and transitions populated.

I was just wondering if this is intentional, and what the difference/intended use of each approach is. As a rule, should I be using the second approach? Or are both valid?

— Reply to this email directly or view it on GitHub https://github.com/zettajs/ZettaKit/issues/23.

benpackard commented 8 years ago

I see, thanks for the clarification.