Comments (10)
Thanks a lot for your suggestion. I just updated the README. 41983a3 It looks much better now.
I'm not sure about adding a .map()
function. If we do so then someone might ask for a .filter()
function next and at some point we end up with a lot of operators which will bloat the bundle for everyone.
Currently the map()
operator isn't even public. It's just a test helper for now. https://github.com/chrisguttandin/subscribable-things/blob/41983a368f1936fbd349595d632126f442ea0d77/test/helpers/map.js
I wonder if there is already a collection of operators that could be reused somehow.
from subscribable-things.
Thanks for all the links. It looks like it's a solved problem. ;-) Should we then close this issue? Or am I missing something?
from subscribable-things.
Hi Dmitry,
there is already a generic function for listening to events.
Here is the part in the README that talks about it: https://github.com/chrisguttandin/subscribable-things#ontarget-eventtarget-type-string-options-boolean--addeventlisteneroptions-subscribablethingevent.
Here is the integration test which probably documents it better:
subscribable-things/test/integration/on.js
Lines 115 to 134 in a1aa54a
Does that help with your use case?
from subscribable-things.
Right
import { on, map } from 'subscribable-things'
map(on(window, 'hashchange'), e => window.location.hash)
A couple of off-topics, if you don't mind.
- Zen-observable defines
.map
method for observables, so that it's not necessary to requiremap
. Wdyt? - Now titles in docs are a bit heavy:
on(target: EventTarget, type: string, options?: boolean | AddEventListenerOptions): SubscribableThing
The keywords get lost in type definitions, makes it a bit hard to find.
Would it make sense to making it more lightweight as:
on(target, type, options?)
on(target: EventTarget, type: string, options?: boolean | AddEventListenerOptions): SubscribableThing<Event>
from subscribable-things.
Looks nice! Yeah, I also doubt about map
. Observable proposal discussion converges to minimal possible implementation, which makes the most sense.
As for the operators library - good idea. In value-ref I came to Ref.from(anyReactiveSource)
method, mimicking Array.from
for observables.
But there indeed seems to be missing a small lib for observables with minimal set of operators and reactive sources (value/object/list). Like tiny rxjs, or reactive lodash. Sort of less proprietary vue reactivity.
from subscribable-things.
Maybe we could create a package called pipeable-operators
(the name is still available) which draws some inspiration from RxJS.
It could provide some operators and a pipe()
function which takes a SubscribableThing
(or any other standards compliant Observable
) as a first parameter and a list of operators to apply. The return value would be another SubscribableThing
.
const newObservable = pipe(
oldObservable,
map((value) => value + 2),
filter((value) => value % 2 === 0)
);
Like in RxJS an operator would be a function which takes an Observable
and returns another one.
But it almost feels unrealistic to me that something like this doesn't exist yet. 🤷♂️
from subscribable-things.
I like the idea, but I think that is rxjs/operators we're talking about, unless there's a point for a separate portable lib with minimal set of indispensable ones. map
, filter
, take
, ... That reminds mutant for actual Observables.
Yeah, it can also possibly subscribe to asyncIterables
as well? Or that's a separate concern though.
from subscribable-things.
To the point there is:
from subscribable-things.
I guess, yes.
from subscribable-things.
Alright, I'm going to close it. Please feel free to open a new issue if you have another idea how this library could be extended or improved.
from subscribable-things.
Related Issues (20)
- An in-range update of rollup is breaking the build 🚨 HOT 2
- An in-range update of babel7 is breaking the build 🚨
- An in-range update of karma is breaking the build 🚨 HOT 1
- An in-range update of karma is breaking the build 🚨 HOT 1
- An in-range update of commitizen is breaking the build 🚨 HOT 1
- An in-range update of rollup is breaking the build 🚨 HOT 1
- An in-range update of tslint-config-holy-grail is breaking the build 🚨 HOT 1
- An in-range update of commitizen is breaking the build 🚨
- An in-range update of rollup is breaking the build 🚨 HOT 2
- An in-range update of tslint-config-holy-grail is breaking the build 🚨 HOT 1
- An in-range update of rollup is breaking the build 🚨 HOT 1
- An in-range update of karma is breaking the build 🚨 HOT 1
- An in-range update of kefir is breaking the build 🚨 HOT 1
- An in-range update of karma-browserstack-launcher is breaking the build 🚨 HOT 1
- An in-range update of tslint-config-holy-grail is breaking the build 🚨 HOT 1
- Thank YOUUU HOT 1
- Render out observable HOT 7
- Improvements HOT 7
- Mention alternatives in readme
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from subscribable-things.