33 lines
503 B
JavaScript
33 lines
503 B
JavaScript
|
import {compose} from '@avocado/core';
|
||
|
|
||
|
import {simpleState, Trait} from '../trait';
|
||
|
|
||
|
const decorate = compose(
|
||
|
simpleState('x'),
|
||
|
simpleState('y'),
|
||
|
);
|
||
|
|
||
|
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) {}
|