raveclassic / frp-ts

Functional reactive values-over-time
MIT License
80 stars 8 forks source link

feat: compatible with svelte by default #36

Open Fyzu opened 2 years ago

Fyzu commented 2 years ago

Frp almost completely compatible with svelte, except for a moment with a subscription.

Svelte uses simple store contract.

type Store = { subscribe: (subscription: (value: any) => void) => (() => void), set?: (value: any) => void }

It seems to me that you can make a separate method for subscribing for a Time like .watch(time => {}) for internal usage, and adopt subscribe to .subscribe(value => {}).

This way we will get compatibility with svelte and it will be more understandable for users who want to work with frp as a reactive library.

raveclassic commented 2 years ago

I'm afraid this diverges from the main idea of change propagation in the lib - don't propagate values, propagate changes. We also already have a standard-compatible integration with other reactive libs - Symbol.observable. It seems to me a better way would be for svelte to implement integration with Symbol.observable instead of requiring some specific interface. Moreover, such interface will most likely confuse the users of the lib - when they see the "conventional" subscribe method with a signature saying it propagates values, they'll definitely go this way by habit and ultimately miss all optimizations (skip duplicates, diamond shape etc.).

On the other hand, integration with popular libraries is a right direction, so I think it's better to keep this conversation open until we have some other feedback and/or feature requires for integrating with svelte and other libraries.