Earlier quoted context omitted.
This is an aside but “trifecta but with four” actually has an awesome name: “Superfecta”!
I would probably avoid naming Firebase alternatives with a prefix like “Super” at this time.
Show HN: InstantDB – A Modern Firebase
151–160 of 308 posts
Re: Show HN: InstantDB – A Modern Firebase
#152Earlier quoted context omitted.
Maybe a dumb question, but why do I have to wrap in `db.transact` and `tx.*`? Why can't I just have a proxy object that handles that stuff under the hood? Naively, it seems more verbose than necessary. Also, I like that in Rails, there are ways to mutate just in memory, and then ways to push the change to DB. I can just assign, and then changes are only pushed when I call `save()`. Or if I want to do it all-in-one, I…
This is a great question. We are working on a more concise transaction API, and are still in the design phase. Writing a `user.save()` could be a good idea, but it opens up a question about how to do transactions. For example, saving _both_ user and post together). I could see a variant where we return proxied objects from `useQuery`. What would your ideal API look like?
Imagine that you support the model discussed above where it’s possible to update the local store optimistically without syncing back to the db. Now you’re one missing .save() away from having everything look like it’s working in the frontend when really nothing is persisting. It’s the sort of foot gun that you might regret supporting.
Our model is slightly different in that we require the .save() on objects to create the mutation for the sync. The primary reason is that we’re syncing back to real tables in Postgres and require referential integrity etc to be maintained.
tx((db) => {
const author = new Author(db)
author.save()
article.name = “New name”
article.author = author
article.save()
}
Mutating an object outside of a transaction is a hard error. Doing the mutation in a transaction but failing to call save within the same transaction is a hard error too.Re: Show HN: InstantDB – A Modern Firebase
#153Re: Show HN: InstantDB – A Modern Firebase
#154Re: Show HN: InstantDB – A Modern Firebase
#155Does Instant have a way to merge many frequent updates into fewer Postgres transactions while maintaining high frequency for multiplayer?
Regardless this is super cool for so many other things where you’re modifying more regular app data. Apps often have bugs when attempting to synchronize data across multiple endpoints and tend to drift over time when data mutation logic is spread across the code base. Just being able to treat the data as one big object usually helps even if it seems to go against some principles (like microservices but don’t get me started on why that fails more often than not due to the discipline it requires).
Re: Show HN: InstantDB – A Modern Firebase
#156It seems like that’s what would do best in the marketplace… people seem to be fine with the API of firebase and just want it to be cheaper
Re: Show HN: InstantDB – A Modern Firebase
#157This looks great. We use our own version of something much more naive which allows for the various benefits you have (but yours does more). Ours is also based on Linear but we go all in on mobx like they do too. It’s a great model where we have optimistic updates and a natural object graph to work with in typescript. I’ll have a play with this to see if it could eventually be used as a replacement. Noticed in your do…
Re: Show HN: InstantDB – A Modern Firebase
#158One bit of feedback: Its always appreciated when code examples on websites are complete. Your example isn't complete -- where's the `transact` import coming from, or `useQuery`? Little minor details that go far as your product scales out to a wider user base.
Thank you for the feedback, this makes sense! I updated the example to include the imports: ``` import { init, tx, id } from "@instantdb/react"; const db = init({ appId: process.env.NEXT_PUBLIC_APP_ID, }); function Chat() { // 1. Read const { isLoading, error, data } = db.useQuery({ messages: {}, }); // 2. Write const addMessage = (message) => { db.transact(tx.messages[id()].update(message)); }; // 3. Render! return…