Skip to content

feat: FirebaseObservableMap #539

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

Closed
jpventura opened this issue Jan 23, 2017 · 7 comments
Closed

feat: FirebaseObservableMap #539

jpventura opened this issue Jan 23, 2017 · 7 comments

Comments

@jpventura
Copy link

I was not sure if I should PR this feature or discuss here first.

ObservableMap as a facade to event listeners

Basically I would like to know if we could provide a feature for hide read and write operations behind an ObservableMap. So all we would have to do to access data would be:

// Remote updates immediately send you your view
map.addOnMapChangedCallback(mUserChangedCallback);

// Non blocking operation to update database
Task<User> task = map.create(user);

// Local up-to-date cache
User user = map.get(primaryKey);

Relevant Code:

A detailed description is available at Stack Overflow and a working code at my repository fork.

@puf
Copy link
Contributor

puf commented Jan 23, 2017

Where/how would you use such a ObservableMap?

@jpventura
Copy link
Author

jpventura commented Jan 23, 2017

@puf It is more a readability improvement the functionality.

We are using Firebase in a project and I was trying to prevent the developers of writing too many nested listeners:

  • Emulating Map interface, the read/write became more readable
  • Sequence of tasks became simpler to write
  • Rollback also became simpler, because oldValue is returned by the map and can restored

I was also trying to separate the model from the adapter, mainly due sorting. Instead of create a query reference and download the documents again, I was planning to also implement SortedMap interface.

@puf
Copy link
Contributor

puf commented Jan 23, 2017

A map usually is a key-value collection with unspecified order semantics, where a Firebase DataSnapshot is an ordered key-value collection. So you're losing the ordering information.

Why don't you use the DataSnapshot instead? That also frees you from the adapter overhead, but then ensures you stick to the underlying system model.

I have no doubt you have good reasons for wanting this, but I don't see the advantages in usage. It may be easier to understand if you add some more code snippets on using the ObservableMap, comparing it to how you'd use a DataSnapshot or Firebase...Adapter in the same use-cases.

@samtstern
Copy link
Contributor

samtstern commented Jan 23, 2017

@jpventura thanks for raising an issue to discuss this rather than going straight to a PR, that's always the right thing to do.

I agree with @puf, I am not familiar with this pattern and would like to see some more examples of how it's used and how that compares with normal Firebase usage patterns to understand the developer benefit.

@samtstern
Copy link
Contributor

@jpventura it's been 3 weeks since the last update on this issue and I still am not totally clear on the use case. Hopefully what's being worked on in #544 will expand the extensibility of this library sufficiently to enable you and many other developers. If you think there's something else to be discussed, please comment on this issue and I'll re-open it.

@jpventura
Copy link
Author

jpventura commented Feb 14, 2017

@samtstern, sorry for taking so long to answer, but it has being really hard save time for the open source projects. And yes, PR #544 provides all super powers I need to separate the model from view at the adapter :-)

But I must agree with @puf and I could not find a benefit of using ObservableMap besides code redability, which also can be achieved using Tasks API instead of nested listeners.

@samtstern
Copy link
Contributor

@jpventura cool! Thanks for responding, I think we'll keep this closed and work on getting some form of #544 to happen so you and all the other devs out there can customize more.

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

No branches or pull requests

3 participants