Other Utils
Open External URL
import { openURL } from 'quasar' |
It will take care of the quirks involved when running under Cordova or on a browser, including notifying the user he/she has to acknowledge opening popups.
Debounce Function
If your App uses JavaScript to accomplish taxing tasks, a debounce function is essential to ensuring a given task doesn’t fire so often that it bricks browser performance. Debouncing a function limits the rate at which the function can fire.
Debouncing enforces that a function not be called again until a certain amount of time has passed without it being called. As in “execute this function only if 100 milliseconds have passed without it being called.”
A quick example: you have a resize listener on the window which does some element dimension calculations and (possibly) repositions a few elements. That isn’t a heavy task in itself but being repeatedly fired after numerous resizes will really slow your App down. So why not limit the rate at which the function can fire?
// Returns a function, that, as long as it continues to be invoked, will not |
There’s also a frameDebounce
available which delays calling your function until next browser frame is scheduled to run (read about requestAnimationFrame
).
import { frameDebounce } from 'quasar' |
Throttle Function
Throttling enforces a maximum number of times a function can be called over time. As in “execute this function at most once every X milliseconds.”
import { throttle } from 'quasar' |
(Deep) Copy Objects
A basic respawn of jQuery.extend()
. Takes same parameters:import { extend } from 'quasar'
let newObject = extend([Boolean deepCopy], targetObj, obj, ...)
Watch out for methods within objects.
Generate UID
Generate unique identifiers:import { uid } from 'quasar'
let uid = uid()
// Example: 501e7ae1-7e6f-b923-3e84-4e946bff31a8
Handling event on a DOM event handler
It’s cross-browser.
import { event } from 'quasar' |
Filter
Filter out an array of Objects based on a certain field:
import { filter } from 'quasar' |