Comments (6)
Oh, thanks for reminding me about the existence of this issue 😆
I'll leave it here for now (spent a couple of minutes with ChatGPT):
declare module "caf" {
export class CancelToken {
controller: AbortController | null;
signal: AbortSignal;
constructor(controller?: AbortController);
abort(reason?: any): void;
discard(): void;
// _trackSignalReason(reason: any): void;
}
export function CAF<T, A extends any[]>(
generatorFn: (signal: AbortSignal, ...args: A) => AsyncGenerator<any, T, any>
): (...args: [CancelToken | AbortSignal, ...A]) => Promise<T>;
export function cancelToken(): CancelToken;
export function delay(
tokenOrSignal: CancelToken | AbortSignal | number,
ms?: number
): Promise<string>;
export function timeout(
duration: number,
message?: string
): CancelToken;
export function signalRace(signals: AbortSignal[]): AbortSignal;
export function signalAll(signals: AbortSignal[]): AbortSignal;
export function tokenCycle(): () => CancelToken;
}
I (or someone else) might take it from here and finish it. I'm a bit busy currently but I hope to find some time in the nearest 2-3 months.
from caf.
If it is possible to reproduce the codebase in ES6
The codebase is already ES6 (actually, at least ES2018, in that it uses async generators). For example, here's a
let
keyword being used where I believe it should be used:Line 73 in a2b12de
Specifically, the use of var declarations
I know there's a lot of cult wisdom in the "modern JS" way of thinking, followed by lint rules, that say
var
should never be used. I completely and totally disagree. There's nothing aboutvar
that's "non-ES6".Put simply, I use
var
for any declaration that's at the top-most scope of a function (or module). I uselet
for any declaration that appears inside a block (such asif
orfor
loop). One little exception is when I have a declaration inside atry
that I want to access outside that block, I use avar
there.More info on how I advocate using
var
/let
/const
: https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/apA.md#the-case-for-varI was unsure whether I needed to add let or const to free up memory.
That's not the appropriate reason to decide between these different declaration types. See link above.
However, I need the codebase to be written in a way that is easier for me to understand and work with
I'm sorry you found the codebase too confusing. I wish my code were considered readable by folks. IMO it's much more readable than most codebases I see others write. But I appreciate that you may disagree.
In any case, I won't be rewriting the codebase. The code style I use here is how I've always written OSS code and how I've always taught JS code.
Don't misunderstand me, I do appreciate that you have fixed a very big problem as your project which is open-source. And, I really respect your efforts for JS.
I don't think codebase is entirely confusing or has bad readability. I am not good enough at JS to judge someone's project. Just confusing for the folks who have learned after ES6 and don't know the past of JS. I really don't know it well yet, like your other repo's purpose of the name. So, the problem was mostly about me, not about the codebase.
Sorry, if it was disrespectful to your efforts, I didn't mean that.
@noomorph you're lifesaver. Just in time. Thank you for sharing!
from caf.
@mustafa519 I'm not sure it will work well enough without fixing, but it's worth trying. Share with us the improvements and fixes if you manage to integrate typings into your project
from caf.
I would consider/accept a contribution of one, but I don't plan to make one (I'm not competent enough at TS).
I think I've heard that things like generators are really hard for TS to type properly. But that's just anecdotal and I might be totally wrong about that.
from caf.
I attempted to reproduce the codebase on my local environment, but I ultimately gave up. While I am comfortable writing code in ES6+ with many ESLint rules, I am not an expert in JavaScript and I found the codebase confusing. Specifically, the use of var
declarations and parameter reassignments made it difficult for me to follow the flow of the code. Like, I was unsure whether I needed to add let
or const
to free up memory.
If it is possible to reproduce the codebase in ES6, I would be willing to try to add the necessary Typescript types. However, I need the codebase to be written in a way that is easier for me to understand and work with, as a noob JS developer.
from caf.
If it is possible to reproduce the codebase in ES6
The codebase is already ES6 (actually, at least ES2018, in that it uses async generators). For example, here's a let
keyword being used where I believe it should be used:
Line 73 in a2b12de
Specifically, the use of var declarations
I know there's a lot of cult wisdom in the "modern JS" way of thinking, followed by lint rules, that say var
should never be used. I completely and totally disagree. There's nothing about var
that's "non-ES6".
Put simply, I use var
for any declaration that's at the top-most scope of a function (or module). I use let
for any declaration that appears inside a block (such as if
or for
loop). One little exception is when I have a declaration inside a try
that I want to access outside that block, I use a var
there.
More info on how I advocate using var
/ let
/ const
: https://github.com/getify/You-Dont-Know-JS/blob/2nd-ed/scope-closures/apA.md#the-case-for-var
I was unsure whether I needed to add let or const to free up memory.
That's not the appropriate reason to decide between these different declaration types. See link above.
However, I need the codebase to be written in a way that is easier for me to understand and work with
I'm sorry you found the codebase too confusing. I wish my code were considered readable by folks. IMO it's much more readable than most codebases I see others write. But I appreciate that you may disagree.
In any case, I won't be rewriting the codebase. The code style I use here is how I've always written OSS code and how I've always taught JS code.
from caf.
Related Issues (20)
- Only catch canceled promise HOT 2
- Can't use with create-react-app HOT 28
- Implementing debounce with CAF? HOT 11
- What happens to cancelled generator functions? No leaks? HOT 2
- How to use CAF with Axios' `cancelToken` argument? HOT 5
- Feature request: configurable 'this' context HOT 3
- Unexpected try/catch/finally semantics HOT 11
- Switch cancelToken to AbortSignal HOT 10
- Possible improvement to memory cleanup in signal race/all combinators HOT 1
- AbortController (in Node), integration with CAF? HOT 9
- How can I dynamically detect a CAF-wrapped generator? HOT 4
- ReferenceError: AbortController is not defined HOT 8
- Import Problems — TypeError: (0 , _caf.CAF) is not a function HOT 9
- AbortController not defined using ES Import statements HOT 1
- Cannot set property reason of #<AbortSignal> which has only a getter HOT 6
- Improve error when `signal` isn't passed down correctly to a sub-CAF HOT 1
- explore: should CAF support "async generators"? HOT 2
- update "abortcontroller" to fully use new version of polyfill
- add `signalRace(..)` and `signalAll(..)` helpers
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 caf.