mobx#flow JavaScript Examples

The following examples show how to use mobx#flow. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: uploader.js    From content-components with Apache License 2.0 6 votes vote down vote up
constructor({ apiClient }) {
		this.uploads = [];
		this.apiClient = apiClient;
		this.uploadsInProgress = 0;
		this.uploadConcurrency = 5;
		this.statusWindowVisible = false;
		this.queuedUploads = [];
		this.runningJobs = 0;
		this._batch = 0;
		this.successfulUpload = {};

		this.uploadFile = flow(function * (file, batch) {
			/* eslint-disable no-invalid-this */
			this.uploadsInProgress += 1;
			const uploadInfo = { file, progress: 0, extension: file.name.split('.').pop(), err: null, batch };
			let count = 0;
			this.uploads.forEach(ui => {
				if (ui.batch === batch) {
					count += 1;
				}
			});
			this.uploads.splice(count, 0, uploadInfo);
			try {
				if (this.runningJobs < this.uploadConcurrency) {
					yield this._uploadWorkflowAsync(uploadInfo);
				} else {
					this.queuedUploads.push(uploadInfo);
				}
			} catch (error) {
				const upload = this.uploads.find(
					upload => upload.file === uploadInfo.file
				);
				upload.error = resolveWorkerError(error);
			}
			/* eslint-enable no-invalid-this */
		});
	}
Example #2
Source File: uploader.js    From content-components with Apache License 2.0 6 votes vote down vote up
constructor({ apiClient }) {
		this.uploads = [];
		this.apiClient = apiClient;
		this.uploadsInProgress = 0;
		this.uploadConcurrency = 5;
		this.statusWindowVisible = false;
		this.queuedUploads = [];
		this.runningJobs = 0;
		this._batch = 0;
		this.successfulUpload = {};

		this.uploadFile = flow(function * (file, batch) {
			/* eslint-disable no-invalid-this */
			this.uploadsInProgress += 1;
			const uploadInfo = { file, progress: 0, extension: file.name.split('.').pop(), err: null, batch };
			let count = 0;
			this.uploads.forEach(ui => {
				if (ui.batch === batch) {
					count += 1;
				}
			});
			this.uploads.splice(count, 0, uploadInfo);
			try {
				if (this.runningJobs < this.uploadConcurrency) {
					yield this._uploadWorkflowAsync(uploadInfo);
				} else {
					this.queuedUploads.push(uploadInfo);
				}
			} catch (error) {
				const upload = this.uploads.find(
					upload => upload.file === uploadInfo.file
				);
				upload.error = resolveWorkerError(error);
			}
			/* eslint-enable no-invalid-this */
		});
	}
Example #3
Source File: uploader.js    From content-components with Apache License 2.0 6 votes vote down vote up
constructor({ apiClient, onSuccess, onError }) {
		this.apiClient = apiClient;
		this.onSuccess = onSuccess;
		this.onError = onError;

		this.uploadProgress = 0;

		this.uploadFile = flow((function * (file, title) {
			/* eslint-disable no-invalid-this */
			yield this._uploadWorkflowAsync(file, title);
			/* eslint-enable no-invalid-this */
		}));
	}