Closed benpackard closed 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:
-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.
I see, thanks for the clarification.
Staring with the following
serverSignal
: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
:B. You can collect the devices directly from the
devices
signal: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 theirlinks
andtransitions
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?