A guide to advanced use of reusables

Hey @petter got your book, and thought very useful - particularly for removing a lot of the opaqueness on how Bubble works! Many thanks for all the work you put into getting this together!

Have a question related to reusables and parameters (which wouldn’t have been around when you wrote the book). If you have a moment, I’d be interested in your view on it…
When I have a value that is required by a number of reusables (e.g. the answer to the question ‘Is this user a member?’) I pass the resulting value as a parameter to the reusables (often initially saving the starting value in an invisible group). Then, if there are reusables inside those reusables they also take that parameter value and pass it down, etc.
My assumption is that this is more effective than getting each reusable to go direct to Bubble and ask the question again - e.g. that it’s better to get the answer once, and distribute it. However, at the same time I know that Bubble caches queries, and that it wont ask the same query twice… and as such, perhaps sharing it as parameters is slower than just getting each reusable to ask the query again, as and when they need it? Passing parameter values makes debugging much easier - since if the rules to answer the question changes, it can just be changed in one place - but if passing parameters comes with a performance penalty then the gain from simplicity may not be worth it…

@mark33

Technically it depends a bit on who the user is: if it’s the current user, it will be downloaded to the client regardless of what you do, and the number of reusables won’t make any meaningful difference.

If it’s a different user, it will be downloaded as needed, but will only be downloaded once and stored in the local device until reload.

From a performance perspective, if I’m reading your setup right, that query is already so lightweight, there’s not much you can do to optimize it (i.e. you can pull different tricks to pass the information down, but it’s all happening client-side anyway and the difference is likely not noticeable at all). So I would encourage you to focus on what makes it easier for you as a developer to set up and keep track of (and of course the user experience, although this is more of an under-the-hood question).

Generally, optimizing database queries is more pressing when we’re talking complex, numerous or big searches, but one field on one user is not much to worry about. It makes sense to control when the query is performed (to avoid downloading the data when it’s not needed) but from there on it doesn’t make a big difference.

thanks Petter - makes complete sense.

1 Like