-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Provide side-effect-free version of operators #860
Comments
I thought about this last night. In Babel, I'd much rather import the operator and use I'm generally for this change, but I think that What if it were something like import {Observable} from 'rxjs/Observable';
import 'rxjs/with/map';
import 'rxjs/with/filter'; and for direct operator imports: import {Observable} from 'rxjs/Observable';
import {map} from 'rxjs/operator/map';
import {filter} from 'rxjs/operator/filter'; |
@Blesh I'm in favor of flipping so that the side-effect free operator is in |
But the act of importing anything under it is literally acting like a function with side-effects. It's executing code that has side-effects.
|
@Blesh I more meant that literally being a verb felt wrong to me, but a noun version of the verb would feel better. But I don't really have a standard or convention to point to to justify my feelings, and I haven't thought of a better name (other than |
I'm fine optimizing for the future and moving the modules with side-effects into a separate directory. so rather than |
|
@IgorMinar no no no, go back to what you suggested with |
I realize @Blesh proposed |
rxjs/add/map reads as add map to rxjs. rxjs/patch/map reads as patch map to rxjs. I guess both are fine. "add" is one char shorter. I'm fine with either. Let's have Ben decide.
|
One of my biggest weakness is always about naming class, variable, module, etcs whatever, especially in English 😓 . Personally bit prefer patch though it's somewhat longer than add. (or mutate? update? not sure.) |
Okay, my pick is Reasons:
... also I'm hope to make a |
LGTM |
It is Decided. |
This change adds a subfolder inside of operator which contains a module to correspond with each operator, which when imported, will automatically patch the corresponding operator to the Observable prototype. Closes ReactiveX#860
This change adds a subfolder inside of operator which contains a module to correspond with each operator, which when imported, will automatically patch the corresponding operator to the Observable prototype. Closes ReactiveX#860
As an alternative, you can expose patching as separate functionality for observables. import {op1} from "rx/op1";
import {op2} from "rx/op2";
Observable.add({op1, op2}); Isn't that bad, it means the logic for adding the method to the observable prototype is kept in one place and we're exporting functions that can be used with I don't feel strongly about it - just want to mention it's a viable alternative here. |
This change adds a subfolder inside of operator which contains a module to correspond with each operator, which when imported, will automatically patch the corresponding operator to the Observable prototype. Closes ReactiveX#860
@benjamingr wouldn't that just be: Object.assign(Observable.prototype, { op1, op2 }) The sucky thing is no matter how you do this, if you want modular operators, you end up mutating the prototype. The only other thing I can think of is some sort of static observable factory method to which you pass your operators and it gives you back a new instance of a subclass of Observable... something sort of like: Observable.factory = (operatorHash, staticMethodsHash) => {
function DynamicObservable() {
Observable.call(this);
}
DynamicObservable.prototype = Object.create(Observable.prototype);
DynamicObservable.prototype.constructor = DynamicObservable;
if (operatorHash) {
Object.assign(DynamicObservable.prototype, operatorHash);
}
if (staticMethodsHash) {
Object.assign(DynamicObservable, Observable, staticMethodsHash);
} else {
Object.assign(DynamicObservable, Observable);
}
return DynamicObservable;
} Then use it like: const MyObservable = Observable.factory({ op1, op2 }); Still kinda gross, but at least you're not mutating a prototype of a shared class. |
@benjamingr The primary motivation for the import-based-side-effect approach is that TypeScript 1.8 is planning to support re-opening and adding to types for modules that patch other modules. This is possible because imports must be static, whereas using a method to patch the prototype would not be. Though I don't think something like |
This change adds a subfolder inside of operator which contains a module to correspond with each operator, which when imported, will automatically patch the corresponding operator to the Observable prototype. Closes ReactiveX#860
It's just all the code duplication that bothers me. I agree that TypeScript and other type systems are a good enough reason to include it statically though. |
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. |
Right now each of the operator modules contain both the operator implementation AND the Observable-patching side effect logic. This prevents smart people like me from being able to safely import an operator without polluting the
Observable
prototype.I think the right default behavior is to keep the side-effect-producing modules named as they already are, in the
operators
folder, and import from a "raw" module that exports the operator implementation.I propose adding an
implementation
folder insideoperators
to contain actual implementations.CC @robwormald @Blesh @IgorMinar
The text was updated successfully, but these errors were encountered: