Skip to content

Commit 60de314

Browse files
author
J00nz
committed
tweenjs#697: Added the ability to override the internal "now" function using the "setNow" function.
1 parent eb07dd2 commit 60de314

File tree

8 files changed

+52
-10
lines changed

8 files changed

+52
-10
lines changed

dist/tween.amd.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ define(['exports'], (function (exports) { 'use strict';
215215
},
216216
});
217217

218-
var now = function () { return performance.now(); };
218+
var _nowFunc = function () { return performance.now(); };
219+
var now = function () {
220+
return _nowFunc();
221+
};
222+
function setNow(nowFunction) {
223+
_nowFunc = nowFunction;
224+
}
219225

220226
/**
221227
* Controlling groups of tweens
@@ -1139,6 +1145,7 @@ define(['exports'], (function (exports) { 'use strict';
11391145
Group: Group,
11401146
Interpolation: Interpolation,
11411147
now: now,
1148+
setNow: setNow,
11421149
Sequence: Sequence,
11431150
nextId: nextId,
11441151
Tween: Tween,
@@ -1398,6 +1405,7 @@ define(['exports'], (function (exports) { 'use strict';
13981405
exports.now = now;
13991406
exports.remove = remove;
14001407
exports.removeAll = removeAll;
1408+
exports.setNow = setNow;
14011409
exports.update = update;
14021410

14031411
Object.defineProperty(exports, '__esModule', { value: true });

dist/tween.cjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,13 @@ var Easing = Object.freeze({
217217
},
218218
});
219219

220-
var now = function () { return performance.now(); };
220+
var _nowFunc = function () { return performance.now(); };
221+
var now = function () {
222+
return _nowFunc();
223+
};
224+
function setNow(nowFunction) {
225+
_nowFunc = nowFunction;
226+
}
221227

222228
/**
223229
* Controlling groups of tweens
@@ -1141,6 +1147,7 @@ var exports$1 = {
11411147
Group: Group,
11421148
Interpolation: Interpolation,
11431149
now: now,
1150+
setNow: setNow,
11441151
Sequence: Sequence,
11451152
nextId: nextId,
11461153
Tween: Tween,
@@ -1400,4 +1407,5 @@ exports.nextId = nextId;
14001407
exports.now = now;
14011408
exports.remove = remove;
14021409
exports.removeAll = removeAll;
1410+
exports.setNow = setNow;
14031411
exports.update = update;

dist/tween.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ declare class Group {
184184
}
185185

186186
declare const now: () => number;
187+
declare function setNow(nowFunction: Function): void;
187188

188189
/**
189190
* Utils
@@ -470,6 +471,7 @@ declare const exports: {
470471
};
471472
};
472473
now: () => number;
474+
setNow: typeof setNow;
473475
Sequence: typeof Sequence;
474476
nextId: typeof Sequence.nextId;
475477
Tween: typeof Tween;
@@ -719,4 +721,4 @@ declare const exports: {
719721
};
720722
};
721723

722-
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };
724+
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };

dist/tween.esm.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ var Easing = Object.freeze({
213213
},
214214
});
215215

216-
var now = function () { return performance.now(); };
216+
var _nowFunc = function () { return performance.now(); };
217+
var now = function () {
218+
return _nowFunc();
219+
};
220+
function setNow(nowFunction) {
221+
_nowFunc = nowFunction;
222+
}
217223

218224
/**
219225
* Controlling groups of tweens
@@ -1137,6 +1143,7 @@ var exports = {
11371143
Group: Group,
11381144
Interpolation: Interpolation,
11391145
now: now,
1146+
setNow: setNow,
11401147
Sequence: Sequence,
11411148
nextId: nextId,
11421149
Tween: Tween,
@@ -1383,4 +1390,4 @@ var exports = {
13831390
update: update,
13841391
};
13851392

1386-
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, update };
1393+
export { Easing, Group, Interpolation, Sequence, Tween, VERSION, add, exports as default, getAll, nextId, now, remove, removeAll, setNow, update };

dist/tween.umd.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@
219219
},
220220
});
221221

222-
var now = function () { return performance.now(); };
222+
var _nowFunc = function () { return performance.now(); };
223+
var now = function () {
224+
return _nowFunc();
225+
};
226+
function setNow(nowFunction) {
227+
_nowFunc = nowFunction;
228+
}
223229

224230
/**
225231
* Controlling groups of tweens
@@ -1143,6 +1149,7 @@
11431149
Group: Group,
11441150
Interpolation: Interpolation,
11451151
now: now,
1152+
setNow: setNow,
11461153
Sequence: Sequence,
11471154
nextId: nextId,
11481155
Tween: Tween,
@@ -1402,6 +1409,7 @@
14021409
exports.now = now;
14031410
exports.remove = remove;
14041411
exports.removeAll = removeAll;
1412+
exports.setNow = setNow;
14051413
exports.update = update;
14061414

14071415
Object.defineProperty(exports, '__esModule', { value: true });

scripts/write-version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs'
2-
import pkg from '../package.json' assert {type: 'json'}
2+
import pkg from '../package.json' with {type: 'json'}
33

44
const {version} = pkg
55

src/Index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import Easing from './Easing'
1111
import Group from './Group'
1212
import Interpolation from './Interpolation'
13-
import now from './Now'
13+
import now, { setNow } from './Now'
1414
import Sequence from './Sequence'
1515
import Tween from './Tween'
1616
import VERSION from './Version'
@@ -273,13 +273,14 @@ const update = TWEEN.update.bind(TWEEN)
273273

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

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

278278
const exports = {
279279
Easing,
280280
Group,
281281
Interpolation,
282282
now,
283+
setNow,
283284
Sequence,
284285
nextId,
285286
Tween,

src/Now.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
const now = (): number => performance.now()
1+
let _nowFunc: Function = () => performance.now()
2+
3+
const now = (): number => {
4+
return _nowFunc()
5+
}
6+
7+
export function setNow(nowFunction: Function) {
8+
_nowFunc = nowFunction
9+
}
210

311
export default now

0 commit comments

Comments
 (0)