-
-
Notifications
You must be signed in to change notification settings - Fork 347
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
async Init file function: streams and fileAdded events #319
Comments
Agree, |
I tried hard to provide a publishable PR where But this implied crazy code complexity and messy method prototypes (Promise-based / Back on the drawing board, I'll probably propose a new PR iteration introducing only following prototype:
For
|
Maybe you could drop backward compatibility and only support promise based one? Supporting both variants without a BC adds some complexity too. So why not break this and reduce our code base? It will be easier to read ant less likely to make a mistake. You can delete entire test too and rewrite it by your needs. Yes, it might work differently, but it's ok if it does it's job |
But that would force users handling regular files (the majority) to use a Promise-based approach with no gain:
Given that the |
I don't think anyone currently using flow.js is going to upgrade to v3. v2 is already stable and they don't need to upgrade if it works. Though you have the point, we can have sync and async separate methods. I leave this decision for you. You have my support in both cases now 👍 |
I'm in line with @AidasK in general. With this change we will be dropping support for IE11 that anyway will be officially dead in July. What about @ng-flow and @ngx-flow? Shall we maybe issue two versions updated to support v2 and v3 respectively? Or maybe we could keep ng-flow as is and port ngx-flow to v3? @MartinNuc what do you think? |
This is a follow-up (and proper implementation) of flowjs#296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file hit back events firing. (flowjs#319) in general and `fileAdded` in particular (flowjs#271) and the current confusión between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported)
ng-flow will be left with v2 version, since angular v1 is quite dead as well. As for ngx-flow, we still need to finish v3, it's a bit early to integrate it. |
Sound good for me to proceed with this plan :) |
Sorry for going off-topic too but:
About the full picture, a user made a Flow.js fork (I'd say "offensive": no git history, dropped authors & licensing) then created a Vue component which only works with his fork due to API changes. Still that could be a source of inspiration. |
I wasn't aware of it and it's quite popular. Too sad he hasn't contacted us before making this fork, we could have done an awesome collaboration. For sure any inspiration is ok and should be used. I have added @drzraf as a member of the whole @flowjs/developers team, so you should be able to manage every repository. Feel free to create a vue js one if you want. 🍾 For bright flow.js future I have promoted @evilaliv3 to the owner. More of use are involved, the better 🏅 |
This is a follow-up (and proper implementation) of flowjs#296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file hit back events firing. (flowjs#319) in general and `fileAdded` in particular (flowjs#271) and the current confusión between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported)
This is a follow-up (and proper implementation) of flowjs#296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file hit back events firing. (flowjs#319) in general and `fileAdded` in particular (flowjs#271) and the current confusión between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported)
I'd like to further divide events, inspired by WordPress model with its
The distinction between
Do you approve such a road?
¹ Whether or not Rule is : If any of Do you approve such an approach and pursuing the PR in that direction? |
Great table. I think it makes much sense and it could be added to the docs too! Great explanation :) |
In the original post I mentioned moving to This seems great to replace
I went over these libraries:
Some of them work by having Unless you've some opinion on the subject, I'm likely to go with the EventTarget.prototype.addEventListener overloading option. By the way, I'm about to split all the event-handling related code into a distinct file to make Flow.js code more focused and readable. Note: I also feel it'd be good to distinguish between |
I would be against overloading. Let's assume that most of our users are not going to upgrade to v3, so we can just drop support for on/off methods. Anyway it's a simple replacement of So I would go for plan 2. |
As for distinguish of events and hooks. Why not moving hooks to params? Do we really need to bind multiple handlers for one hook? |
The other reason why I want to make breaking changes for this code is that flow.js to be future proof. Of course it's going to break ngx-flow integration, but that's it. We have no other dependencies. New flow.js should be simpler, easier to use and should cause less confusion. By dropping overloading it's for sure going to be simpler |
This is a follow-up (and proper implementation) of flowjs#296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file hit back events firing. (flowjs#319) in general and `fileAdded` in particular (flowjs#271) and the current confusión between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported)
This is a follow-up (and proper implementation) of flowjs#296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file hit back events firing. (flowjs#319) in general and `fileAdded` in particular (flowjs#271) and the current confusión between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported)
This is a follow-up (and proper implementation) of flowjs#296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file hit back events firing. (flowjs#319) in general and `fileAdded` in particular (flowjs#271) and the current confusión between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported)
This is a follow-up (and proper implementation) of flowjs#296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file hit back events firing. (flowjs#319) in general and `fileAdded` in particular (flowjs#271) and the current confusión between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported)
This is a follow-up (and proper implementation) of flowjs#296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file hit back events firing. (flowjs#319) in general and `fileAdded` in particular (flowjs#271) and the current confusión between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported)
## Ability to use asynchronous initFileFn. This is a follow-up (and proper implementation) of #296 (reverted in e867d54) This could be use to initialize a stream, a reader, fetch a remote resource, ... during the FlowFile initialization. `asyncAddFile` and `asyncAddFiles` are introduced which support this mechanism. These function return promises of one (or multiple) FlowFile(s). To implement this: - An AsyncFlowFile class extending a FlowFile is created, overriding the bootstrap part - In order to keep code-duplication low, a filterFileList generator yield files in way common to async and non-async addFiles() functions. The possibly async' nature of initializing file affects events firing. (#319) in general and `fileAdded` in particular (#271) and the current confusion between hooks altering bootstraping and simple events. - fileAdded is now assumed an event. If we detect a return value, a warning is sent. - preFilterFile is introduced and allow filtering the raw file before bootstrap() - postFilterFile is introduced and allow filtering the FlowFile after a (possibly async) bootstrap() - filesAdded is preserved About parameters: - `initFileFn` is only used during bootstrap - If such a helper exists, it's tightly related to addFile* functions. As such, it was deemed adequate to provide it as a parameter to `*addFile*()` (but `opts.initFileFn` is still supported) An `Eventizer` class is added where all the necessary code exist. - Hooks alter code processing and could be `synchronous` or not. - Events are CustomEvent dispatched asynchronously for informative purpose. A warning is triggered if an obsolete event name is used ## Other changes * uploadNextChunk: use transpilation instead of relying upon the each() helper * FlowFile: don't bootstrap within the constructor. This must be done manually now * README/CHANGELOG * Also trigger async hooks in sync-mode (but don't wait for them to return) # tests: - switch uploadSpec to createFakeServer - move some useful helpers related to final file consistency - bugfix. xhr_server.restore() is not enough. Recreating the object fix some failures under particular tests sequences - added new tests for the async initFileFn and related asynAddFile(s) functions - modified tests to take into account changes related to hooks & events * builds
This is a follow-up of #296
In that PR, support was introduced for async
initFileFn
which allows to read from a stream and/or perform other async operation before Flow.js proceed with a given file.One very important aspect of the FlowFile bootstrap is size determination (by default, from the regular
file.size
) in order to compute the number of chunks needed. AinitFileFn
could affect this computation.FlowFile initialization is followed by the
fileAdded
event which serves two purposes:reject this file
Flow.upload()
would fails if theFlowFile.chunks
array was not computed)One issue is that an async
initFileFn
could finish afterfileAdded
fires.So one question is: Should the
initFileFn
function really run if a file is going to be rejected?If yes (eg, because rejection depends upon the number of chunks/file.size), then a PR could be made so that the event is fired after
initFileFn
(even if async). It would movefileAdded
inside FlowFile's bootstrap function unless a nicer and higher-level solution exists (like of more pipeline-like vision of the process). I tend to think there should be less assumptions aboutfile.size
at the beginning of the process (eg: FlowChunks could be built on-demand later) but this hook in its current shape forbids this.Side note about Events: I think that having events to expect a return value makes them more hooks than events. It's a bit counter intuitive and keeps the code from moving to native Events. Not sure they are worth it.
The
fileAdded
native event could just pass the corresponding (read-only) reference to Flow and the FlowFile and the consumer coulddelete
it as well (accessing to the global flow object). It'd be more flexible.The text was updated successfully, but these errors were encountered: