cyremur
cyremur•3y ago

I have to admit I have a guilty pleasure

I have to admit I have a guilty pleasure of OOP. Ideally, I want to have Class Instances in my state that have prototype functions to mutate themselves and/or other objects in state. I know namespaces and passing in the object as a first argument kind of does the same, but it just doesn't look as nice to me. By the looks of it, I should serialize class instances into POJOs for saving with convex, right? So does it make sense to have the following workflow in my mutations?
1. load POJO from convex db
2. deserialize into class instances with functions again
3. do OOP state manipulation magic
4. serialize class instances into POJOs
5. upsert POJOs to convex db
1. load POJO from convex db
2. deserialize into class instances with functions again
3. do OOP state manipulation magic
4. serialize class instances into POJOs
5. upsert POJOs to convex db
6 Replies
nipunn
nipunn•3y ago
Yeah - that general strategy should work. For example, your class could have a constructor that takes in the POJO out of the convex db. There's probably a variety of ways to make it work - that's one. TIL the term POJO. Pretty good one.
cyremur
cyremurOP•3y ago
I did Java for a year and the term POJO is all I remember... anyway, managed to dump my whole redux gamestate as a single document into the convex db, that's enough for today... looking forward to replacing my game action dispatches with convex mutations and hiding the game logic away from frontend
Indy
Indy•3y ago
Re POJO
No description
alexcole
alexcole•3y ago
One more thought here: If you're excited about OOP stuff, it should also be possible to design a full active record style ORM that is implemented on top of the convex db. So you could have classes for all of your types with getters and setters for the various properties that under the hood call db.patch . You could wrap db.get and db.query to return these class instances so you never interact with the POJOs. You'd also probably want a map of _id -> class instance so that instances are reused if you load the same ID twice. I've been thinking about doing this type of thing for a while. Seems like it could be a powerful way to write complex biz logic in Convex.
cyremur
cyremurOP•3y ago
Yeah that sounds pretty cool. Do you have a need for a freelancer building proof of concepts for niche ideas by any chance? 😄
jamwt
jamwt•3y ago
@cyremur would be interesting to explore... can you drop me an email at jamwt@convex.dev and we can investigate the idea in a little more detail?e

Did you find this page helpful?