Skip to content
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

Abort-like mechanism for multiple pending requests #12

Open
niksy opened this issue Feb 28, 2020 · 0 comments
Open

Abort-like mechanism for multiple pending requests #12

niksy opened this issue Feb 28, 2020 · 0 comments
Assignees

Comments

@niksy
Copy link
Owner

niksy commented Feb 28, 2020

{
	data() {
		return {
			queryStack: 0
		}
	},
	async getData (query) {
		const { onQueryInput, queryStack } = this.get();
		const newQueryStack = queryStack + 1;
		this.set({ queryStack: newQueryStack });
		const prevQueryStack = newQueryStack;
		this.set({
		  loading: true
		});
		const results = await onQueryInput(query);
		const currentQueryStack = this.get().queryStack;
		if ( prevQueryStack !== currentQueryStack ) {
			return;
		}
		this.set({ queryStack: 0 });
		// Do it
	}
}

{
	getData: function getData(query) {
		var _this2 = this;

		console.log('hello');

		var _this$get8 = this.get(),
			onQueryInput = _this$get8.onQueryInput,
			queryStack = _this$get8.queryStack;
		var newQueryStack = queryStack + 1;
		var prevQueryStack = newQueryStack;
		this.set({
			queryStack: newQueryStack,
			loading: true
		});
		onQueryInput(query).then(function(results) {
			var currentQueryStack = _this2.get().queryStack;
			console.log(currentQueryStack, prevQueryStack);
			if (prevQueryStack !== currentQueryStack) {
				return;
			}
			_this2.set({
				queryStack: 0,
				loading: false,
				position: null,
				isOpened: results.length !== 0,
				results: results.map(function(result) {
					return _extends({}, result, {
						active: false
					});
				})
			});

			return results;
		});
	}
}
@niksy niksy self-assigned this Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant