From 64174eb0c97711bce8387626d46652a43aedaf53 Mon Sep 17 00:00:00 2001 From: Davlat Date: Fri, 24 Nov 2017 13:05:15 +0500 Subject: [PATCH] * code(core): removed circular `prev` and `next` access on `Tween` * code(Tween): added missed relative code * and some fixes --- CODE_OF_CONDUCT.md | 6 +----- test.js | 4 ++-- ts/Tween.ts | 18 +++++++++++++++--- ts/constants.ts | 4 ++-- ts/core.ts | 7 ------- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index b78e737..4bab65c 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -43,8 +43,4 @@ Project maintainers who do not follow or enforce the Code of Conduct in good fai This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org -<<<<<<< HEAD -[version]: http://contributor-covenant.org/version/1/4/ -======= -[version]: http://contributor-covenant.org/version/1/4/ ->>>>>>> c51a062... * docs(CODE_OF_CONDUCT): added +[version]: http://contributor-covenant.org/version/1/4/ \ No newline at end of file diff --git a/test.js b/test.js index 5dfbae4..6e13a15 100644 --- a/test.js +++ b/test.js @@ -54,7 +54,7 @@ test('Value Interpolation', t => { }) let tween = new Tween(obj) - .to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+1' }, 100) + .to({ a: 1, b: 'B value 2', c: { x: 3 }, d: [4], _e: 5, g: '+=1' }, 100) .start(0) update(0) @@ -114,7 +114,7 @@ test('Value Array-based Interpolation', t => { t.log('Start-value interpolation was done') - tween.update(100) + update(100) }) diff --git a/ts/Tween.ts b/ts/Tween.ts index 28609e2..70d1b54 100644 --- a/ts/Tween.ts +++ b/ts/Tween.ts @@ -498,6 +498,9 @@ class Tween { } } _valuesStart[property] = start; + if (typeof start === 'number' && typeof end === 'string' && end[1] === '=') { + continue + } decompose(property, object, _valuesStart, _valuesEnd); } @@ -805,7 +808,9 @@ class Tween { end.update(value); } else if (typeof end === 'function') { object[property] = end(value); - } else { + } else if (typeof end === 'string' && typeof start === 'number') { + object[property] = start + parseFloat(end[0] + end.substr(2)) * value + } else { recompose(property, object, _valuesStart, _valuesEnd, value, elapsed); } if (Plugins[property] && Plugins[property].update) { @@ -832,7 +837,7 @@ class Tween { this.emit(EVENT_UPDATE, object, elapsed, time); - if (elapsed === 1 || (_reversed && !elapsed)) { + if (elapsed === 1 || (_reversed && elapsed === 0)) { if (_repeat > 0 && _duration > 0) { if (_isFinite) { this._repeat--; @@ -840,7 +845,14 @@ class Tween { if (_yoyo) { this._reversed = !_reversed; - } + } else { + for (property in _valuesEnd) { + let end = _valuesEnd[property] + if (typeof end === 'string' && typeof _valuesStart[property] === 'number') { + _valuesStart[property] += parseFloat(end[0] + end.substr(2)) + } + } + } this.emit(_yoyo && !_reversed ? EVENT_REVERSE : EVENT_REPEAT, object); diff --git a/ts/constants.ts b/ts/constants.ts index 7be4105..c72e5f5 100644 --- a/ts/constants.ts +++ b/ts/constants.ts @@ -61,7 +61,7 @@ const hex2rgb = (all, hex) => { }; export function decomposeString(fromValue: string): any[] { - return fromValue.replace(hexColor, hex2rgb).match(NUM_REGEX).map(v => (isNaNForST(v) ? v : +v)); + return typeof fromValue !== 'string' ? fromValue : fromValue.replace(hexColor, hex2rgb).match(NUM_REGEX).map(v => (isNaNForST(v) ? v : +v)); } // Decompose value, now for only `string` that required @@ -83,7 +83,7 @@ export function decompose(prop, obj, from, to, stringBuffer?) { } } - if (fromValue1[0] !== STRING_PROP) { + if (fromValue1[0] !== STRING_PROP && Array.isArray(fromValue1)) { fromValue1.unshift(STRING_PROP); } if (toValue1[0] !== STRING_PROP) { diff --git a/ts/core.ts b/ts/core.ts index 46bfd4c..b206b04 100644 --- a/ts/core.ts +++ b/ts/core.ts @@ -74,13 +74,6 @@ const add = (tween: any): void => { _tweens.splice(i, 1); } - if (_tweens.length > 0) { - i = _tweens.length - 1; - let tweenPrev = _tweens[i]; - tween.prev = tweenPrev; - tweenPrev.next = tween; - } - _tweens.push(tween); emptyFrame = 0;