avocado-old/packages/entity/traits/positioned.js

33 lines
503 B
JavaScript
Raw Normal View History

2019-03-17 23:45:48 -05:00
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) {}