refactor: Evolving is now a decorator

This commit is contained in:
cha0s 2021-01-28 12:45:26 -06:00
parent 62d2e58701
commit e68ed3b6c4
3 changed files with 50 additions and 31 deletions

View File

@ -1,30 +0,0 @@
import {TickingPromise} from '@avocado/core';
import {TransitionResult} from '@avocado/timing';
import {Trait} from '@avocado/traits';
export default () => class Evolving extends Trait {
methods() {
return {
transition: (props, duration, easing) => {
const result = new TransitionResult(
this.entity,
props,
duration,
easing,
);
return new TickingPromise(
(resolve) => {
resolve(result.promise);
},
(elapsed) => {
result.tick(elapsed);
},
);
},
};
}
};

View File

@ -1,4 +1,7 @@
import {gatherWithLatus} from '@latus/core';
import {
decorateWithLatus,
gatherWithLatus,
} from '@latus/core';
export {
cancelAnimationFrame,
@ -18,6 +21,9 @@ export default {
'@avocado/resource/resources': gatherWithLatus(
require.context('./resources', false, /\.js$/),
),
'@avocado/resource/resources.decorate': decorateWithLatus(
require.context('./resources/decorators', false, /\.js$/),
),
'@avocado/traits': gatherWithLatus(
require.context('./traits', false, /\.js$/),
),

View File

@ -0,0 +1,43 @@
import {TickingPromise} from '@avocado/core';
import TransitionResult from '../../transition/result';
export default (Entity) => class EvolvingEntity extends Entity {
describe() {
const description = super.describe();
description.methods.transition = {
args: [
{
label: 'Properties',
type: 'object',
},
{
label: 'Duration',
type: 'number',
},
],
label: 'Transitions properties for $2 seconds.',
type: 'void',
};
return description;
}
transition(props, duration, easing) {
const result = new TransitionResult(
this.entity,
props,
duration,
easing,
);
return new TickingPromise(
(resolve) => {
resolve(result.promise);
},
(elapsed) => {
result.tick(elapsed);
},
);
}
};