Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Async userdata loading #222

Closed
little-brother opened this issue Oct 24, 2019 · 2 comments
Closed

Async userdata loading #222

little-brother opened this issue Oct 24, 2019 · 2 comments
Labels

Comments

@little-brother
Copy link

I want to mark some days depending on the result of the fetch being executed for each redraw.
I inspected the code and found that it could be done through a change of fill-method e.g.

function fill (target) {
	var root_element = target.__pickmeup.element,
	...
	if (!options.userdata && options.update_userdata) {
		return options.update_userdata(function (err, res) {
			options.userdata = err || res; 
			fill(target);
		});
	}
	...
	options.userdata = null;
	dom_dispatch_event(target, 'fill');
}

And usage

pickmeup('.single', {
	update_userdata: (cb) => setTimeout(() => cb(err, [1,2,3]), 1000),
	render: function (date) {
		return (this.userdata || []).indexOf(+date.getDay()) != -1 ? 
			{class_name: 'red'} : 
			{};
	}
});

But I don't like it :( Maybe there is a more elegant solution?

@nazar-pc
Copy link
Owner

Try adding listener to fill event and just call .update() method whenever you want to re-render datepicker.

@little-brother
Copy link
Author

Thanks, I'll try it :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants