Skip to content

perfectsense/brightspot-js-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOTE: Starting with 3.0.0, bsp-js-utils is an ECMAScript 6 module instead of a RequireJS module. If you need an AMD version, work in the 2.x.x branch.

Installation

Using Bower:

bower install bsp-utils

Manually:

Usage

onDomInsert

bsp_utils.onDomInsert(String selector, Object callbacks)

Triggers the given callbacks when an element matching the given selector is inserted into the DOM. The callbacks argument can contain:

  • Function(Array or HTMLElement items) beforeInsert
  • Function(HTMLElement item) insert
  • Function(Array or HTMLElement items) afterInsert

This method is most often used to implement a plugin that works like a Web Component (demo).

plugin

See the separate plugin documentation.

throttle

bsp_utils.throttle(Number interval, Function throttledFunction)

Throttles the given throttledFunction so that it executes at most given interval (in milliseconds). This method is most often used to rate-limit noisy events like scroll (demo).

debounce

bsp_utils.debounce(Number wait, Function debouncedFunction, Boolean immediate)

Debounces the given debouncedFunction so that it postpones the execution of the code for the given wait (in milliseconds). If immediate is truthy, the function is executed at the beginning of the debounce. An example usage of debouncing is, in a lazy-loaded UI, often you want to prevent double-clicks on a "load more" button from firing 2 requests to the server.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published