37 lines
551 B
JavaScript
37 lines
551 B
JavaScript
import {compose} from '@avocado/core';
|
|
|
|
import {simpleState, Trait} from '../trait';
|
|
|
|
const decorate = compose(
|
|
simpleState('x', {
|
|
track: true,
|
|
}),
|
|
simpleState('y', {
|
|
track: true,
|
|
}),
|
|
);
|
|
|
|
class PositionedBase extends Trait {
|
|
|
|
static defaultState() {
|
|
return {
|
|
x: 0,
|
|
y: 0,
|
|
};
|
|
}
|
|
|
|
get position() {
|
|
return [
|
|
this.state.get('x'),
|
|
this.state.get('y'),
|
|
];
|
|
}
|
|
|
|
set position([x, y]) {
|
|
this.state = this.state.merge({x, y});
|
|
}
|
|
|
|
}
|
|
|
|
export class Positioned extends decorate(PositionedBase) {}
|