Skip to content

Latest commit

 

History

History
224 lines (204 loc) · 6.78 KB

DevHelpers.md

File metadata and controls

224 lines (204 loc) · 6.78 KB

Dev-Helpers library

Import

This library cannot be used without having imported the universalsmoothscroll-min.js script in your project first.
This library is also a module so each function you see below must be imported before you can use it.

For example:

  //The name of these and more other functions is in the table below.
  import {
    isValidStepLengthCalculator
  } from "YOUR_JAVASCRIPT_FOLDER/universalsmoothscroll-dev-helpers-min.js";

  //From here I can start using the imported functions.
  ...

Usage

This library contains functions that should help you with the more challenging aspect of the Universal Smooth Scroll API (e.g. how to create a correct stepLengthCalculator).
This library is meant to be used during the development phase of your website only and it's not internally used by the API, so it should be removed from the project before the deployment phase (nothing will happens if you forgot to, don't worry).

In this library each function has this structure: functionName(mandatoryParam1, ... , mandatoryParamN, options).
The options parameter must either be completely omitted or fully specified.

For instance:

//Here we fully specify the "options" parameter.
let result1 = await isValidStepLengthCalculator(
  myFunction1,
  { //This is the "options" parameter
    container: myContainer,
    totalScrollAmount: 500,
    timeout: 1000
  }
);

//Omitting the options parameter is also valid.
let result2 = await isValidStepLengthCalculator(myFunction1);

if(!result1 || !result2) {
  //Throw error...
  //Fix myFunction1...
}

Note:
A bold input parameter's name means that it's a mandatory input.
An italic input parameter's name means that it's an optional parameter.

Name Type Input Parameters Default values Description
isValidStepLengthCalculator async fun Tests the passed function by performing a dummy scroll-animation (no actual scroll takes place).
Errors/warnings will be logged in the console during the testing process.
Returns true if the passed function is a valid stepLengthCalculator.
Returns false otherwise.
options container _pageScroller
totalScrollAmount 100
timeout 5000
getBrowserRefreshRate async Tests if both the _framesTime and the _framesTimes variable have not been altered and if so calculates the browser's refresh rate.
More specifically, it returns the highest number of times that the requestAnimationFrame can be called per second.


Input parameters details

The following table describes every entry of the Input Parameters column of the table above.

Name Parameter Name Parameter Type Parameter Description
isValidStepLengthCalculator fun Function A function you want to use as a stepLengthCalculator.
options container Object An Element or the Window.
totalScrollAmount Number The total amount of pixel to scroll you want the dummy scroll-animation to test your stepLengthCalculator againist.
timeout Number The number of milliseconds after which the test forcefully returns a result.