Giter Site home page Giter Site logo

Comments (17)

asciimike avatar asciimike commented on May 23, 2024

@kermankohli Yep, this would definitely be useful. I put some thought into this earlier, and my original thought was to use separate refs, so you would create a FirebaseTableViewDataSource and then add a section to it, and a section would contain a ref (or more likely a query). The approach mentioned above could allow for just a single ref, assuming you wanted to filter the data into sections based on the content of a single field.

This might fit in well for our eventual support for better client side filtering, so definitely on the roadmap after auth. It requires an array of arrays to support sections, adding inSection:indexPath.section adding numberOfSections... as [metaArray count] and then updating the correct array every time an event is raised. PR's welcome if you wanted to try before we got to it :)

from firebaseui-ios.

kermankohli avatar kermankohli commented on May 23, 2024

@mcdonamp Alright, thanks for that! I'm not implementing Firebase right now but will be looking to move in about a month - do you reckon it'd be implemented by then?

from firebaseui-ios.

asciimike avatar asciimike commented on May 23, 2024

Thanks to @pmodernme, it might be earlier: #13

from firebaseui-ios.

kermankohli avatar kermankohli commented on May 23, 2024

@mcdonamp looks pretty good, thanks @pmodernme! 👍

from firebaseui-ios.

pmodernme avatar pmodernme commented on May 23, 2024

from firebaseui-ios.

kermankohli avatar kermankohli commented on May 23, 2024

Hey guys just had a question,

If the refQuery was users/john/tasks (which contains the IDs of all the users), how would filtering/sorting work in that case?

from firebaseui-ios.

pmodernme avatar pmodernme commented on May 23, 2024

@kermankohli
As my sectioning fork is currently...

If you don't set the predicate, or the sort descriptors (set them to nil), it will sort the snapshots alphabetically by key.

If you set the sortDescriptors (this is an array of NSSortDescriptors), it will sort first by the zeroth sort descriptor, then the first, and so on. The sort descriptor queries the snapshot. So you could do:

@[[[NSSortDescriptor alloc] initWithKey:@"value.origin_date" ascending:NO]];
This will order by the origin_date child of the snapshot, with the largest value at the top.

or

@[[[NSSortDescriptor alloc] initWithKey:@"key" ascending:YES]];
This will order by the key of the snapshot (the last key path of the ref).

You have to use a key path like value.name to query the value.

Predicates work much in the same way. You set the predicate to an NSPredicate.

[NSPredicate predicateWithFormat:@"%K == %@", @"value.hidden", @NO];

Only snapshots with the child hidden with a value of FALSE will be shown.

I hope that helps!

from firebaseui-ios.

kermankohli avatar kermankohli commented on May 23, 2024

@pmodernme

Thanks for such a detailed write up! Just read back on what I wrote and I ended up confusing my self 👎

What I meant to say was if the refQuery was /users/john/tasks/ (which contains an array of tasks who's ids correspond to the task class) then how would sorting work, because the values themselves haven't been fetched.

Sorry for the confusion before!

from firebaseui-ios.

asciimike avatar asciimike commented on May 23, 2024

What you're asking about is join functionality on top of the filtering, which we don't currently support. We're investigating something similar to what Firebase-Util offers in that respect, but, to be honest, doing all of that client side is really not something that we're interested in doing from a performance standpoint.

from firebaseui-ios.

kermankohli avatar kermankohli commented on May 23, 2024

Yeah it's kinda an edge case which might not be worth developing for. Would it be fine if I structured my data to look like /tasks/john/taskX rather /tasks/(tasks from /users/john/tasks/)?

from firebaseui-ios.

asciimike avatar asciimike commented on May 23, 2024

It's a totally valid use case, it's just not something we support out of the box on the backend (being the type of NoSQL database we are). It's fine if you structure it that way, the issue is just that potentially pulling down all that task data and sorting it client side could be a pretty expensive operation.

Typically I recommend only pulling down the minimum amount of data required to sort/filter client side and then attach listeners on the relevant tasks/objects and grab those more full changes. Typically, for instance, you aren't filtering off the title or the description of the task (and those are relatively big), but you might be filtering off timestamps/tags, so keep the title/description in tasks/$taskID while putting other info in users/john/tasks/$taskID or similar.

from firebaseui-ios.

kermankohli avatar kermankohli commented on May 23, 2024

Right gotchya. In my case I need to sort/filter by 5 keys, so in that case I'll need to store all that information in users/john/tasks/$taskID?

from firebaseui-ios.

pmodernme avatar pmodernme commented on May 23, 2024

Ah! I have something similar in my own app. You have to sort or fetch by
something in the snapshot.
In mine, I have a list of subscriptions with basically just a timestamp,
Boolean, and an id for the data it relates too. The predicate is based on
the Boolean, and the sort is based on the timestamp. Then I use another ref
to populate the cell.

from firebaseui-ios.

kermankohli avatar kermankohli commented on May 23, 2024

That makes sense! Doesn't it lead to duplication of data though? Or is this normal when you denormalize data (I'm new to this haha)?

from firebaseui-ios.

asciimike avatar asciimike commented on May 23, 2024

Yes, it can, though this is more normal in a NoSQL database--disk space is cheap, your time is not. It's effectively creating indices rather than relying on the DB to do so. Plus, with multi-writes in Firebase, it's easy to keep these values in sync.

from firebaseui-ios.

asciimike avatar asciimike commented on May 23, 2024

Closing because pull #13 deals with this

from firebaseui-ios.

cgossain avatar cgossain commented on May 23, 2024

I've built an NSFetchedResultsController type solution for the Firebase Realtime Database, and I've just open sourced it. I've been using this in a few of my production apps for some time now.

https://github.com/cgossain/FirebaseResultsController

I'd love to hear your thoughts.

from firebaseui-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.