Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: braposo/react-text-loop
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.2.1
Choose a base ref
...
head repository: braposo/react-text-loop
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 9 commits
  • 5 files changed
  • 5 contributors

Commits on Dec 2, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7bcaa5b View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c81378b View commit details
  3. format changes

    kenime committed Dec 2, 2019
    Copy the full SHA
    787d31e View commit details
  4. fix linting issues

    kenime committed Dec 2, 2019
    Copy the full SHA
    34ac45f View commit details

Commits on Dec 7, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    052150b View commit details

Commits on Dec 14, 2019

  1. Merge pull request #43 from kenime/master

    Fix issues with timeout
    braposo authored Dec 14, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    44adf05 View commit details
  2. Bump serialize-to-js from 3.0.0 to 3.0.1 (#45)

    Bump serialize-to-js from 3.0.0 to 3.0.1
    braposo authored Dec 14, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fcabcfa View commit details
  3. Copy the full SHA
    cf766b3 View commit details
  4. 2.3.0

    braposo committed Dec 14, 2019
    Copy the full SHA
    68e78f5 View commit details
Showing with 960 additions and 191 deletions.
  1. +2 −1 .eslintrc
  2. +21 −21 package.json
  3. +12 −0 src/components/TextLoop.tsx
  4. +19 −13 src/utils.ts
  5. +906 −156 yarn.lock
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -24,7 +24,8 @@
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": true }
]
],
"import/extensions": ["warn", "never"]
},
"settings": {
"react": {
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-text-loop",
"version": "2.2.1",
"version": "2.3.0",
"description": "Create an animated loop of a list of text for your headings",
"main": "./lib/index.js",
"module": "es/index.js",
@@ -17,7 +17,7 @@
"dev": "yarn run clean && cross-env BABEL_ENV=commonjs babel src -d lib --watch",
"start": "parcel examples/index.html -d examples/dist --cache-dir examples/cache --open",
"lint": "eslint src/ --ext .js,.tsx,.ts",
"prepublishOnly": "yarn run test && yarn run clean && yarn run build",
"prepublishOnly": "yarn run test && yarn run lint && yarn run ts:check && yarn run clean && yarn run build",
"test": "jest",
"test:coverage": "jest --coverage",
"ts:check": "tsc -p tsconfig.json --allowJs false --noEmit --emitDeclarationOnly false"
@@ -53,32 +53,32 @@
},
"homepage": "https://github.com/braposo/react-text-loop#readme",
"devDependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/plugin-proposal-class-properties": "^7.7.0",
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/plugin-transform-modules-commonjs": "^7.7.0",
"@babel/preset-env": "^7.7.1",
"@babel/preset-react": "^7.7.0",
"@babel/preset-typescript": "^7.7.2",
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-proposal-object-rest-spread": "^7.7.4",
"@babel/plugin-transform-modules-commonjs": "^7.7.5",
"@babel/preset-env": "^7.7.6",
"@babel/preset-react": "^7.7.4",
"@babel/preset-typescript": "^7.7.4",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/react": "^9.4.0",
"@types/jest": "^24.0.23",
"@types/node": "^12.12.8",
"@types/react": "^16.9.11",
"@types/node": "^12.12.17",
"@types/react": "^16.9.16",
"@types/react-dom": "^16.9.4",
"@types/react-motion": "^0.0.29",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"@typescript-eslint/eslint-plugin": "^2.11.0",
"@typescript-eslint/parser": "^2.11.0",
"babel-eslint": "^10.0.3",
"babel-loader": "^8.0.6",
"cross-env": "^6.0.3",
"eslint": "^6.6.0",
"eslint": "^6.7.2",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.6.0",
"eslint-plugin-import": "^2.18.2",
"eslint-config-prettier": "^6.7.0",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.16.0",
"eslint-plugin-react": "^7.17.0",
"jest": "^24.9.0",
"npm-run-all": "^4.1.5",
"parcel-bundler": "^1.12.4",
@@ -87,8 +87,8 @@
"react-dom": "^16.12.0",
"rimraf": "^3.0.0",
"source-map-loader": "^0.2.4",
"ts-jest": "^24.1.0",
"typescript": "^3.7.2",
"ts-jest": "^24.2.0",
"typescript": "^3.7.3",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
},
12 changes: 12 additions & 0 deletions src/components/TextLoop.tsx
Original file line number Diff line number Diff line change
@@ -94,6 +94,18 @@ class TextLoop extends React.PureComponent<Props, State> {
this.tickDelay = requestTimeout(() => {
this.tickLoop = requestTimeout(this.tick, currentInterval);
}, delay);
} else {
this.setState((state, props) => {
const { currentWordIndex: _currentWordIndex } = state;

return {
currentInterval: Array.isArray(props.interval)
? props.interval[
_currentWordIndex % props.interval.length
]
: props.interval,
};
});
}
}

32 changes: 19 additions & 13 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
declare global {
interface Window {
mozRequestAnimationFrame: any;
oRequestAnimationFrame: any;
msRequestAnimationFrame: any;
mozCancelRequestAnimationFrame: any;
webkitCancelRequestAnimationFrame: any;
oCancelRequestAnimationFrame: any;
msCancelRequestAnimationFrame: any;
mozRequestAnimationFrame;
oRequestAnimationFrame;
msRequestAnimationFrame;
mozCancelRequestAnimationFrame;
webkitCancelRequestAnimationFrame;
oCancelRequestAnimationFrame;
msCancelRequestAnimationFrame;
}
}

declare interface Handle {
value: number | void;
}

const requestAnimFrame = ((): Function => {
if (typeof window !== "undefined") {
return (
@@ -24,10 +28,12 @@ const requestAnimFrame = ((): Function => {
);
}

return (): void => {};
return (): void => {
/* return empty function */
};
})();

export type RequestTimeout = number | void;
export type RequestTimeout = object | number | void;
/*
* Behaves the same as setTimeout except uses requestAnimationFrame() where possible for better performance
* @param {function} fn The callback function
@@ -52,7 +58,7 @@ export const requestTimeout = function(

const start = new Date().getTime();

let value: number | void = 0;
const handle: Handle = { value: 0 };

function loop(): number | void {
const current = new Date().getTime();
@@ -62,12 +68,12 @@ export const requestTimeout = function(
if (delta >= delay) {
fn.call(null);
} else {
value = requestAnimFrame(loop);
handle.value = requestAnimFrame(loop);
}
}

value = requestAnimFrame(loop);
return value;
handle.value = requestAnimFrame(loop);
return handle;
};

/**
Loading