Skip to content

Polymer utility functions, mixins, modules and styles.

Notifications You must be signed in to change notification settings

StartPolymer/s-utils

Repository files navigation

StartPolymer Utilities

PRs welcome

Polymer utility functions, mixins, modules and styles.

Install

bower i StartPolymer/s-utils -S

Import

Polymer 1.0

<link rel="import" href="../bower_components/s-utils/utils-es5/throttle.html">

Polymer 2.0

<link rel="import" href="../bower_components/s-utils/utils/throttle.html">

Functions

throttle() from throttle.html

Creates a throttled function that only invokes callback at most once per every wait milliseconds.

See David Corbacho's article for details over the differences between throttle and debounce techniques.

// Limiting the api call thrice a second.
var resultFunction = S.Utils.throttle(_apiCall, 1000, 3);

// Calling the closure function in every 100 milliseconds.
setInterval(function () {
  resultFunction();
}, 100);

Inspired by https://stackoverflow.com/a/42975776/1614237

throttlePerFrame() from throttle.html

Creates a throttled function that only invokes callback at most once per frame using requestAnimationFrame. Ideal using for mouse, resize, scroll events.

window.addEventListener('resize', S.Utils.throttlePerFrame(this._onOptimizedResize));

Inspired by raf-throttle

timestamp() from date.html

Returns a timestamp measured in milliseconds, accurate to five thousandths of a millisecond (5 microseconds).

S.Utils.timestamp()

Modules

Browser from browser.html

Module that provides a number of properties for detection of browser types and features.

S.Utils.Browser.hasTouchScreen
S.Utils.Browser.isIE
S.Utils.Browser.onAndroid