Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Headless tests, minor fixes and patches
Browse files Browse the repository at this point in the history
  • Loading branch information
dalisoft committed Feb 25, 2019
1 parent d91b36f commit b00df25
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 38 deletions.
15 changes: 15 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"exclude": ["node_modules/**", "bundles/**", "performance/**", "logo/**", "examples/**"],
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"shippedProposals": true
}
]
],
"plugins": [
"@babel/plugin-proposal-class-properties"
]
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cache:
notifications:
email: false
node_js:
- "8"
- 8
before_install:
- npm i -g npm@^6.0.0
before_script:
Expand Down
4 changes: 2 additions & 2 deletions examples/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<body>
<div class="container">
</div>
<script src="../full/Tween.js"></script>
<script src="../bundled/Tween.js"></script>
<script>

var body = document.body;
Expand All @@ -40,7 +40,7 @@
body.textContent = JSON.stringify(object);
}).start();

var tween = new TWEEN.Tween({x:'i am here 600 year'}).to({x:'i am here 200 year'}, 2000).delay(3000).on('update', function (object) {
var tween = new TWEEN.Tween({x:'600 y.o'}).to({x:'200 y.o'}, 2000).delay(3000).on('update', function (object) {
//round(object);
body.textContent = JSON.stringify(object);
}).start();
Expand Down
5 changes: 2 additions & 3 deletions examples/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@

<div id="container"></div>

<script src="../full/Tween.js"></script>
<script src="../../es6-tween-plugins/renderer/render.js"></script>
<script !src="../../es6-tween-plugins/transform/transform.js"></script>
<script src="../bundled/Tween.js"></script>
<script src="https://unpkg.com/[email protected]/render.min.js"></script>
<script>
TWEEN.autoPlay(true);

Expand Down
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"prepublishOnly": "yarn lint && yarn doc && yarn doc-md",
"doc": "npx jsdoc --readme README.md --configure jsdoc.json --verbose",
"doc-md": "npx jsdoc2md src/** > API.md",
"test": "yarn lint && yarn source && npx ava --verbose",
"test": "yarn lint && npm run source && npx ava",
"lint": "npx eslint ./src",
"lint-fix": "npx eslint ./src --fix"
},
Expand Down Expand Up @@ -55,9 +55,22 @@
"husky": "^1.3.1",
"jsdoc": "^3.5.5",
"jsdoc-to-markdown": "^3.1.0-1",
"puppeteer": "^1.12.2",
"rollup": "^1.2.3",
"rollup-plugin-babel": "^4.3.2",
"uglify-js": "^3.4.9"
},
"dependencies": {}
"dependencies": {},
"ava": {
"verbose": true,
"require": [
"esm"
],
"babel": {
"extensions": [
"js",
"mjs"
]
}
}
}
17 changes: 1 addition & 16 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,6 @@ export default {
},
context: 'this',
plugins: [
babel({
babelrc: false,
exclude: ['node_modules/**', 'bundles/**', 'performance/**', 'logo/**', 'examples/**'],
presets: [
[
'@babel/preset-env',
{
modules: false,
shippedProposals: true
}
]
],
plugins: [
'@babel/plugin-proposal-class-properties'
]
})
babel()
]
}
7 changes: 4 additions & 3 deletions src/Tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
add,
now,
Plugins,
remove
remove,
isRunning
} from './core'
import Easing from './Easing'
import Interpolation from './Interpolation'
Expand Down Expand Up @@ -101,7 +102,7 @@ class Tween {
object = this.object = NodeCache(node, object, this)
}
this._valuesEnd = null
this._valuesStart = {}
this._valuesStart = Array.isArray(object) ? [] : {}

this._duration = 1000
this._easingFunction = defaultEasing
Expand Down Expand Up @@ -733,7 +734,7 @@ class Tween {

let delta = time - _prevTime
this._prevTime = time
if (delta > TOO_LONG_FRAME_MS) {
if (delta > TOO_LONG_FRAME_MS && isRunning()) {
time -= delta - FRAME_MS
}

Expand Down
16 changes: 10 additions & 6 deletions src/core.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global process */
import { requestAnimationFrame, root } from './shim'
import { requestAnimationFrame, cancelAnimationFrame, root } from './shim'

/**
* Get browser/Node.js current time-stamp
Expand Down Expand Up @@ -54,6 +54,7 @@ let _onRequestTick = []
const _ticker = requestAnimationFrame
let emptyFrame = 0
let powerModeThrottle = 120
let _tick

const onRequestTick = (fn) => {
_onRequestTick.push(fn)
Expand Down Expand Up @@ -86,10 +87,8 @@ const add = (tween) => {
emptyFrame = 0

if (_autoPlay && !isStarted) {
_ticker(update)
_tick = _ticker(update)
isStarted = true
} else {
_requestTick()
}
}

Expand All @@ -110,7 +109,7 @@ const onTick = (fn) => _tweens.push({ update: fn })
* TWEEN.FrameThrottle(60)
*/
const FrameThrottle = (frameCount = 120) => {
powerModeThrottle = frameCount
powerModeThrottle = frameCount * 1.05
}

/**
Expand All @@ -137,6 +136,7 @@ const autoPlay = (state) => {
*/
const removeAll = () => {
_tweens.length = 0
cancelAnimationFrame(_tick)
}

/**
Expand Down Expand Up @@ -178,6 +178,9 @@ const remove = (tween) => {
if (i !== -1) {
_tweens.splice(i, 1)
}
if (_tweens.length === 0) {
cancelAnimationFrame(_tick)
}
}

/**
Expand All @@ -193,11 +196,12 @@ const update = (time = now(), preserve) => {
if (emptyFrame >= powerModeThrottle) {
isStarted = false
emptyFrame = 0
cancelAnimationFrame(_tick)
return false
}

if (_autoPlay && isStarted) {
_ticker(update)
_tick = _ticker(update)
} else {
_requestTick()
}
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Interpolation from './Interpolation'
import Tween from './Tween'
import Selector from './selector'
import Interpolator from './Interpolator'
import * as utils from './constants'
import './shim'
export {
Plugins,
Expand All @@ -39,5 +40,6 @@ export {
FrameThrottle,
Tween,
Easing,
Interpolation
Interpolation,
utils
}
Loading

0 comments on commit b00df25

Please sign in to comment.