opral / inlang-message-sdk

0 stars 0 forks source link

Roadmap for persisting sdk v2 MessageBundles #70

Open jldec opened 1 month ago

jldec commented 1 month ago

MESDK-109

Capturing here for wider readability.

This tasklist describes the steps toward full persistence and apis for v2 MessgaeBundles. This is part of an ongoing effort to streamline the sdk architecture as described in https://github.com/opral/inlang-message-sdk/issues/15.

SDK reactive API(3)

samuelstroschein commented 1 month ago

Regarding the framework adapter:

Exposing RxJS Observables has high interop. The only "adapter" (just a binding function) that UI frameworks would need is to .subscribe.

In Solid land this is as simple as:

function Component(){
  const message = from(project.query.message.subscribe("blabla"))
  return <>{message()}</>
}

https://docs.solidjs.com/reference/reactive-utilities/from

In React land

function Component(){
  const message = useObservable(project.query.message.subscribe("blabla"))
  return <>{message}</>
}

https://github.com/crimx/observable-hooks

Hence, I think going with RxJS for internal reactivity and exposing observables via .subscribe is our easiest path to put the reactivity discussions behind us. cc @martin.lysk1

martin-lysk commented 1 month ago

Agree - any thoughts on this one from you @jan.johannes

jldec commented 1 month ago

Thanks for the feedback 🙏
Here's a quick TL;DR of how I'm thinking about the api layers for now.
Internal means below the === line.

UI code
- - - - - - - - - - - - - - - - - -
UI framework adapter
- - - - - - - - - - - - - - - - - -
generic reactive api: RxJS ?
===================================
js subscribe (e.g. to CRUD events)
- - - - - - - - - - - - - - - - - -
messages CRUD api (not reactive)
- - - - - - - - - - - - - - - - - -
store api (DB/files)

To be extra clear @martin.lysk1, I don't think we want reactivity in the bottom layers, even knowing that we want observable database queries in the future.

At the time when we have lix apis for change-tracking on a DB, we can look at DBs with watchable queries, but I did not interpret @samuel.stroschein's suggestion for RxJS to mean that we should implement this in our v2 store using RxJS internally.

The v2 store is a very bare-bones database designed to live in text files versioned by git while we continue working on lix.

samuelstroschein commented 4 weeks ago

What is the generic reactive api? JS subscribe can be applied to any api no?

for example:
project.settings.subscribe()

i would prob also change the api to project.{api}.get|set|subscribe:

project.settings.get()
project.settings.set()
project.settings.subscribe()

but I did not interpret @samuel.stroschein's suggestion for RxJS to mean that we should implement this in our v2 store using RxJS internally.

Yep. Doesn't have to use rxjs internally BUT Ui state always needs to be correct. wiring everything manyally will be hard ( i assume). you can try a non rxjs implementation. if bugs pop up, we will know why

jldec commented 4 weeks ago

change the api to project.{api}.get|set|subscribe


What is the generic reactive api? JS subscribe can be applied to any api no?

This was just my interpretation of the app-facing RxJS api suggestion you made earlier. I agree that we should start with a basic subscribe first.

samuelstroschein commented 4 weeks ago

change the api to project.{api}.get|set|subscribe

Do you have a sense of where query() might fit in this model?

No. Except that we can prob drop the .query.* namespace.

project.messages.get()
project.messages.update()
project.messages.*
project.messages.subscribe()
project.lintReports.update()
project.lintReports.subscribe()

I do wonder how we might incorporate @felixhaeberle 's request for projectList.subscribe in MESDK-36

Yep. probably with the same pattern. Although, we break tree-shaking here.

listProjects.get()
listProjects.subscribe()
felixhaeberle commented 4 weeks ago

Yep. probably with the same pattern.

Agree 👍