refactor: Evolving is now a decorator
This commit is contained in:
parent
62d2e58701
commit
e68ed3b6c4
|
@ -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);
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
};
|
|
@ -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$/),
|
||||
),
|
||||
|
|
43
packages/timing/src/resources/decorators/entity.js
Normal file
43
packages/timing/src/resources/decorators/entity.js
Normal 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);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user