Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class AsyncBindingBehavior {
- private bind(binding: any, source: any): void {
- binding.originalupdateTarget = binding.updateTarget;
- binding.updateTarget = (target: Promise<any>) => {
- // When we have a promise
- if (typeof target.then === 'function') {
- // Set temp value to loading so we know its loading
- binding.originalupdateTarget('Loading...');
- // Process the promise
- target
- .then((response) => {
- // Make sure the binding target is still available
- if (binding.originalupdateTarget)
- binding.originalupdateTarget(response);
- })
- .catch((error) => binding.originalupdateTarget('Promise failed'));
- } else
- binding.originalupdateTarget(target);
- };
- }
- private unbind(binding: any) {
- binding.updateTarget = binding.originalupdateTarget;
- binding.originalupdateTarget = null;
- }
- }
Add Comment
Please, Sign In to add comment