How can rxjava manage a mutable collection? - reactive-programming

I have a view which shows a list of devices connected with my phone, as new devices added and some devices disconnected, how can I create a subject with which I receive the current device list on the first subscription and subsequently receive add & remove events of the list.
Currently my implementation is a getDeviceList() method and a subject emits list change events. An event contains a type and a device properties. Is there any better implementation that can remove the additional event class?

You can avoid the event wrapper if you have different Observables for different event types: one for add events and one for remove events.

Related

Broadcast stream in Flutter only responds to one of multiple listeners

I receive data from a BLE unit and have a broadcast stream exposed by a singleton locator (Get_It) to my application.
From the data, I want to build several small display widgets that need to display different information based on the same data stream, however, only the last of my 3 widgets listens to, and receives the stream information.
I was under the impression that, a broadcast stream makes itself available to more than one listener, however, this is clearly not the case, unless I have it wrong.
For reference, here's the exposure via my sessionManager:
Stream<dynamic> get pairAndListen => AppSDK.unit
.pair()
.asBroadcastStream()
AppSDK.unit is a call to a Flutter plugin, that exposes the BLE's characteristics by the manufacturer's supplied SDK for both Android and iOS (reactive_ble and the likes will not work here as it's IP locked behind their SDK's).
As per my understanding setting it up as a broadcast stream should allow multiple listeners receive the feedback?
An example of my widgets:
widget_1.dart
Widget1(stream: sessionManager.pairAndListen)
widget_2.dart
Widget2(stream: sessionManager.pairAndListen)
What I'm actually doing, the widgets are on a dashboard, wrapped in a Column(), each receiving the stream from the sessionManager, however, only the last one of the 3 widgets work; the other two is completely ignored.
If I wrap my Column() with a single StreamBuilder and pass the result from the callback to each of the widgets, it obviously works as there's only one listener, however, I want each of my widgets to manage the response differently within themselves.
Am I missing something in regards to the use of asBroadcastStream?

Firebase Observe() Clarification

If you for instance do
DataBase.database().refrence().observe(.valueChanged....
//code here
)
more then one time in the same spot, does this create a stack of observers? I want to make sure I only have 1 observer per spot. Does calling this method multiple times create more then one observer?
If you attach multiple observers to the same location in the database, the SDK is smart enough to internally only register with the server to receive updates to that location once. It doesn't duplicate the amount of data sent to the app. All your observers at that location will still receive the updates, so you will need to unregister each to stop receiving updates.

How can I send event for all mounted tags?

riot.js 2.2
By guides on official site of riot.js I have to call something like
tag.trigger('event_name')
where the tag is the instance of certain listener.
But what must i do to trigger event for all tags?
Has riot.js any implementation for this issue or I have to resolve it manually(by keeping all listeners instances)?
Riot has no implementation of keeping references to all event listeners. So, if you want to execute trigger on them directly, you'll have to implement it yourself.
However, I would recommend to use another solution for notifying multiple event listeners.
If you want to let know multiple tags that an event has occured, you can use a shared observable and handle events on this observable. See this SO question. This way, you don't need to keep refereneces to all event listeners, instead, event listeners need to keep reference to single observable ('event aggregator').
You can also try RiotControl as a shared observable.

Handling Invitations for Programmatic Turn-Based Game

Thanks to the updates to GameKit API in iOS 6, I am finally able to implement my turn-based board game the way it should be, complete with turn timeouts and better programmatic creation of matches. However, I am running into an issue that I cannot seem to solve. My desire is to have Game Center running entirely invisible to the end-user, so that everything is programmatic and uses my own custom interfaces.
Therefore, I use my own custom table view to display matches, not the default GKTurnBasedMatchmakerViewController. Right now, I have no problem displaying open matches using the -loadMatchesWithCompletionHandler: method. I also use a custom screen to create a match, with a direct creation for auto-match (not a problem) and a table view that loads Game Center friends of the localPlayer for invitation. Since the playersToInvite attribute can now be filled with playerID's, this is possible in iOS 6.
My main problem is handling the invitation on the recipient's side. Lets say I invite Bob to play my game in a two-player match. Right now I can't seem to find a notification for a new invite on Bob's end. The -handleTurnEvent: only gets called for existing matches or if the banner notification is touched (which I can't guarantee the user will do), and -handleInviteFromGameCenter: does nothing for me in this case.
The only way I have come up with to detect new invites and thus update my custom game view controller is to call the -loadMatchesWithCompletionHandler: method and check for new matches in which lastTurnDate of the invited participant is nil and against an existing array of open matches. I run this check about every 10 seconds in the background since I can't find a notification in GKTurnBasedEventHandler that is called when a new invite is received. Please help!
EDIT: In the end, I have just implemented a pull-to-refresh functionality. There is no way without implementing polling or some other method that would just waste the user's data on their phone, so on demand refreshing is the most ideal solution in my opinion.
Please see this : GKInvite Reference and more specifically inviteHandler.
You just need to register an inviteHandler which will be called after Bob accepts the invite in GK/GC.
T.

How does the ViewModel get notified on data item's property change?

The ViewModel can notify the View about property change by raising property change event. If the underlying data (for example, a Plain class which do not implement IPropertyChange) changes, how can ViewModel get notified?
If the underlying data (for example, a Plain class which do not implement IPropertyChange) changes, how can ViewModel get notified?
It cannot, there has to be a mechanism in place to do the notification. The most likely cause is a POCO that is used in one region (or module) of the application is also being used in another, i.e. a loosely coupled master-detail situation. If you are "sharing" the same instance of a POCO like this, then it is unlikely that you haven't also implemented change notification in it. If you have implemented change notification, then a change in one module of the application will automatically be visible to the other module (they are both looking at the same object) and anything that watches for that change notification (like a binding subsystem) will do its thing and pick up the changes.
If you have two separate instances of the same data and one gets updated, the other will not know about it. This also happens when your VM requests data via the Model, and the Model retrieves the data from a disconnected data source like a database or a web service. You don't know when the underlying data has been changed, once again you need to implement a change notification system. You can also take another aproach with this - let the user change the data, then do a fresh grab of the data before saving the user's changes, and if the underlying data has changed while the user was working then you can notify the user and take the appropriate action (or let the user choose the appropriate thing to do).
Does this answer your question? Or do you care to elaborate more about what you are wanting to know?