-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RxPY 3.0 #269
Comments
Should we also rename the observer interface (abc) from |
The code on the current branch seems to completely remove the method based operators. Is the plan the following :
Meaning that v2 would allow people to migrate from method operators to pipe, and v3 has only the pipe method operator ? I think I should find some time to work on documentation. A dedicated documentation of the RxPY APIs, more than the readme is needed. When people ask me where is the doc, I can only give them the ReactiveX link, but this far from ideal. There is an open issue on that part (#101). Do we keep it or do we close it and open a new one ? To get things step by step I can propose several PR instead of a big one (e.g one for initial sphinx structure, then one per "part"). It would allow to publish things as they are available instead of waiting - potentially - for months until everything is ready. Concerning the observer interface (an all naming in general), I prefer to stick as much as possible to the ReactiveX documentation, and in this case the observable contract (http://reactivex.io/documentation/contract.html). So I would stick with the current naming since it is the official names, made PEP8 compliant. |
RxPY 2 haven't got a stable release yet, and I haven't got time for maintaining it. The pipe operator will only work for RxPY 3 since all operators needs to be partially appliable. So the current plan is to skip RxPY 2 and move directly to RxPY 3. I'm not happy with having 2 different ways of doing things (method chaining and pipelining), and it takes much more effort to maintain. So after hours of refactoring I gave up having both. It got very complicated keeping method chaining with Subjects, GroupedObservale, ConnectableObservable etc. AFAIK RxJS removed method chaining for v6, so it should be the way to go anyways. Migration is actually pretty easy. RxPY 2 also removed the scheduler parameter for all operators, and it was replaced with a scheduler parameter for subscribe that would set the scheduler for all operators in the chain, once and for all. But I got very unsure if this was the right thing to do, so for RxPY 3, I have reintroduced the scheduler for operators again. For UI frameworks etc, you can still set the scheduler once for subscribe. As for the docs, I'm in favor of closing #101 as the PR did way too much, and got impossible for me to merge. README.md should be kept to a minimum (what not how) and just refer to the docs. Docstrings are now in Google style, and I would not be happy changing them to something else. |
Yes, from the rapid look that I had on RxPY 2, the scheduler implementation was much more complex than on RxPY 1. Personally I am fine with the v1 API for schedulers. So I will be happy to get the same one on v3 :)
Ok, that's great, documentation seems to be already there for all operators. BTW it seems to be duplicated both at rx/operators/init.py and rx/core/operators/*.py. |
Please feel free to make the docs the way you think would give the best result :) Yes, docstrings are currently duplicated. The API is rx/operators/init.py and rx/init.py (for creation such as from_iterable, empty, never, throw, from_range ...). We might want to document the inner function instead in rx/core/operators since that is what you will inspect after making an operator instance such as |
Hi, obs = rx.amb(o1, o2, o3) as well as: obs = o1.pipe(amb(o2, o3)) Should we assume that every operators which takes as input one or more observables will be available in rx and rx.operators (i.e. merge_all, combine_latest, ...)? |
Yes, I think we should provide them both e.g as with the imperative |
Ok, that's sound good, thank you. |
One really cool thing about the new syntax is that it's very easy to create new operators based on existing ones. E.g. def _all(predicate: Predicate) -> Callable[[Observable], Observable]:
filtering = ops.filter(lambda v: not predicate(v))
mapping = ops.map(lambda b: not b)
some = ops.some()
def all(source: Observable) -> Observable:
return source.pipe(
filtering,
some,
mapping
)
return all In this case we can in fact make it "point-free" by using the from rx.core import pipe
def _all(predicate: Predicate) -> Callable[[Observable], Observable]:
filtering = ops.filter(lambda v: not predicate(v))
mapping = ops.map(lambda b: not b)
some = ops.some()
return pipe(
filtering,
some,
mapping
) This is where the new syntax really shows it's true strength. This makes the new RxPY much more extensible and can offer much more code reuse than before. |
That's awesome ! It's really like plug in some pieces of pipes together. I guess it makes easier to build new custom operators too by removing the need to monkey patch at runtime Observable with the extension decorator. |
If you agree, I will try to convert the examples too during the next days. By the way, good job for the massive update ! 👍 |
Do you mean the ones in the examples directory or in the readme ? I will work on the readme the coming days to move parts of it in the documentation. So please do not touch the readme :) |
forget my comment. The examples in the readme are already using pipe. |
Yes, the rewrite was so much more than I expected. Very happy to get the tests working again, and super happy for all the help. Thanks for the great work! Added the PR to check that the branch is building at Travis CI. I have now moved master into release/v2.0.x, so we are basically ready to merge v3 into master. Todo:
I would also like to change time handling from using millisecond (integer) to seconds (float) to match the Python stdlib time handling, but this may be too much to rewrite, and could add to the confusion. But it's a good opportunity now that the changes are so huge anyways. What do you think? |
Concerning time handling, it seems that each implementation uses a different unit. So it can make sense to make it pythonic on RxPY, (seconds encoded as a float). |
I agree too, this is the right oportunity to switch to seconds.
Don't worry, I don't touch readme :D Buidling documentation is far outside my competence anyway. I was rather thinking of 'demos' in RxPY/examples. |
Another thing to simplify time handling would be to just remove absolute scheduling and datetimes. Do anyone ever use it? With only relative time handling we could also remove timedeltas and only use seconds (float). It would make the impl. and typing ( |
Personally I don't use absolute scheduling but maybe we should be careful about that ? I really don't know. I've just checked quickly the operators relying on time and it seems the switch to float would effect only the schedulers implementation ? (and the doc for these operators of course) Will the tests continue to work since the messages are specified in 'virtual time'? |
Even with absolute scheduling the timeouts will be converted to seconds by the scheduler ( Tests will work since they are using virtual time, but we should add a ".0" to the numbers. |
Alright so this should be OK to simplify. |
I think so too. I'll keep the TestScheduler working with ticks (msecs) to avoid any changes there |
Maybe we should rename as well |
In what operators would you remove absolute times ? For me an operator like timeout must support an absolute time as input. Dealing with time is always tricky, even with python (local time vs UTC, and DST). So I would keep absolute timeouts to avoid conversions to relative times when e.g. the time information is already a timedate. |
I'll leave in the datetimes. Removing them turned out to be much harder than I thought. |
I'm actually removing result_mapper for RxPY/rx/core/observable/staticobservable.py Line 206 in 5c2b6b5
I was thinking this class should be obsolete now, but not 100% sure ? |
Yes, obsolete. See the top comment in the file. I will delete it. Time rewrite to seconds is now checked in, so please do some sanity checking if you have any code. The tests are also running at seconds and works since they are running in virtual time, thus 200 becomes 200.0 seconds, so the tests don't really test fractions such as 0.5 seconds. |
I've just tested with small examples (e.g. with |
Btw. refactored the subscribe logic and use of File "/Users/dbrattli/Developer/GitHub/RxPY-reactivex/rx/core/operators/map.py", line 31, in on_next
obv.on_next(result)
File "/Users/dbrattli/Developer/GitHub/RxPY-reactivex/rx/core/observerbase.py", line 19, in on_next
self._on_next_core(value)
File "/Users/dbrattli/Developer/GitHub/RxPY-reactivex/rx/core/autodetachobserver.py", line 16, in _on_next_core
self._observer.on_next(value)
File "/Users/dbrattli/Developer/GitHub/RxPY-reactivex/rx/core/observerbase.py", line 19, in on_next
self._on_next_core(value)
File "/Users/dbrattli/Developer/GitHub/RxPY-reactivex/rx/core/operators/filter.py", line 34, in on_next
observer.on_next(value) is now reduced to: File "/Users/dbrattli/Developer/GitHub/RxPY-reactivex/rx/core/operators/map.py", line 31, in on_next
obv.on_next(result)
File "/Users/dbrattli/Developer/GitHub/RxPY-reactivex/rx/core/autodetachobserver.py", line 24, in on_next
self._on_next(value)
File "/Users/dbrattli/Developer/GitHub/RxPY-reactivex/rx/core/operators/filter.py", line 34, in on_next
observer.on_next(value) Getting rid of the |
Good job! I get a trace two times less than before for an example involving |
Closing this now @jcafhe and @MainRo, as the feature branch has been merged with master. You can still push to master, but please make PRs if you are unsure about the changes you are making. You don't need a PR for every doc change, but please involve any stakeholders for the code you are changing. I will add a new Issue for tracking the continued work. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Currently working on RxPY 3.0 which is heavily inspired by RxJS 6.0. Need help with fixing things after code refactoring. New features:
result_mapper
) will be removed to make implementation simpler.What remains needs to be done is:
rx/operators/__init__.py
.rx/.__init__.py
.PRs are very much welcome to the feature/rxpy-3.0 branch.
The text was updated successfully, but these errors were encountered: