Skip to content

Commit

Permalink
tweenjs#697: Added the ability to override the internal "now" functio…
Browse files Browse the repository at this point in the history
…n using the "setNow" function.
  • Loading branch information
J00nz committed Dec 18, 2024
1 parent eb07dd2 commit 60de314
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 10 deletions.
10 changes: 9 additions & 1 deletion dist/tween.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,13 @@ define(['exports'], (function (exports) { 'use strict';
},
});

var now = function () { return performance.now(); };
var _nowFunc = function () { return performance.now(); };
var now = function () {
return _nowFunc();
};
function setNow(nowFunction) {
_nowFunc = nowFunction;
}

/**
* Controlling groups of tweens
Expand Down Expand Up @@ -1139,6 +1145,7 @@ define(['exports'], (function (exports) { 'use strict';
Group: Group,
Interpolation: Interpolation,
now: now,
setNow: setNow,
Sequence: Sequence,
nextId: nextId,
Tween: Tween,
Expand Down Expand Up @@ -1398,6 +1405,7 @@ define(['exports'], (function (exports) { 'use strict';
exports.now = now;
exports.remove = remove;
exports.removeAll = removeAll;
exports.setNow = setNow;
exports.update = update;

Object.defineProperty(exports, '__esModule', { value: true });
Expand Down
10 changes: 9 additions & 1 deletion dist/tween.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ var Easing = Object.freeze({
},
});

var now = function () { return performance.now(); };
var _nowFunc = function () { return performance.now(); };
var now = function () {
return _nowFunc();
};
function setNow(nowFunction) {
_nowFunc = nowFunction;
}

/**
* Controlling groups of tweens
Expand Down Expand Up @@ -1141,6 +1147,7 @@ var exports$1 = {
Group: Group,
Interpolation: Interpolation,
now: now,
setNow: setNow,
Sequence: Sequence,
nextId: nextId,
Tween: Tween,
Expand Down Expand Up @@ -1400,4 +1407,5 @@ exports.nextId = nextId;
exports.now = now;
exports.remove = remove;
exports.removeAll = removeAll;
exports.setNow = setNow;
exports.update = update;
4 changes: 3 additions & 1 deletion dist/tween.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ declare class Group {
}

declare const now: () => number;
declare function setNow(nowFunction: Function): void;

/**
* Utils
Expand Down Expand Up @@ -470,6 +471,7 @@ declare const exports: {
};
};
now: () => number;
setNow: typeof setNow;
Sequence: typeof Sequence;
nextId: typeof Sequence.nextId;
Tween: typeof Tween;
Expand Down Expand Up @@ -719,4 +721,4 @@ declare const exports: {
};
};

export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };
11 changes: 9 additions & 2 deletions dist/tween.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,13 @@ var Easing = Object.freeze({
},
});

var now = function () { return performance.now(); };
var _nowFunc = function () { return performance.now(); };
var now = function () {
return _nowFunc();
};
function setNow(nowFunction) {
_nowFunc = nowFunction;
}

/**
* Controlling groups of tweens
Expand Down Expand Up @@ -1137,6 +1143,7 @@ var exports = {
Group: Group,
Interpolation: Interpolation,
now: now,
setNow: setNow,
Sequence: Sequence,
nextId: nextId,
Tween: Tween,
Expand Down Expand Up @@ -1383,4 +1390,4 @@ var exports = {
update: update,
};

export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };
10 changes: 9 additions & 1 deletion dist/tween.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@
},
});

var now = function () { return performance.now(); };
var _nowFunc = function () { return performance.now(); };
var now = function () {
return _nowFunc();
};
function setNow(nowFunction) {
_nowFunc = nowFunction;
}

/**
* Controlling groups of tweens
Expand Down Expand Up @@ -1143,6 +1149,7 @@
Group: Group,
Interpolation: Interpolation,
now: now,
setNow: setNow,
Sequence: Sequence,
nextId: nextId,
Tween: Tween,
Expand Down Expand Up @@ -1402,6 +1409,7 @@
exports.now = now;
exports.remove = remove;
exports.removeAll = removeAll;
exports.setNow = setNow;
exports.update = update;

Object.defineProperty(exports, '__esModule', { value: true });
Expand Down
2 changes: 1 addition & 1 deletion scripts/write-version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'fs'
import pkg from '../package.json' assert {type: 'json'}
import pkg from '../package.json' with {type: 'json'}

const {version} = pkg

Expand Down
5 changes: 3 additions & 2 deletions src/Index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Easing from './Easing'
import Group from './Group'
import Interpolation from './Interpolation'
import now from './Now'
import now, { setNow } from './Now'
import Sequence from './Sequence'
import Tween from './Tween'
import VERSION from './Version'
Expand Down Expand Up @@ -273,13 +273,14 @@ const update = TWEEN.update.bind(TWEEN)

// NOTE! Make sure both lists of exports below are kept in sync:

export {Easing, Group, Interpolation, now, Sequence, nextId, Tween, VERSION, getAll, removeAll, add, remove, update}
export {Easing, Group, Interpolation, now, setNow, Sequence, nextId, Tween, VERSION, getAll, removeAll, add, remove, update}

const exports = {
Easing,
Group,
Interpolation,
now,
setNow,
Sequence,
nextId,
Tween,
Expand Down
10 changes: 9 additions & 1 deletion src/Now.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const now = (): number => performance.now()
let _nowFunc: Function = () => performance.now()

const now = (): number => {
return _nowFunc()
}

export function setNow(nowFunction: Function) {
_nowFunc = nowFunction
}

export default now

0 comments on commit 60de314

Please sign in to comment.