refactor: useSelfEntity was just a specialization of usePropertyChange

This commit is contained in:
cha0s 2019-04-24 17:03:50 -05:00
parent 429a0efb68
commit b9eb887225
3 changed files with 2 additions and 22 deletions

View File

@ -6,7 +6,6 @@ import {Vector} from '@avocado/math';
import contempo from 'contempo';
// 1st party.
import {usePropertyChange} from '../hooks/use-property-change';
import {useSelfEntity} from '../hooks/use-self-entity';
const decorate = compose(
contempo(`
@ -43,7 +42,7 @@ const decorate = compose(
);
const SelfEntityComponent = ({app}) => {
const selfEntity = useSelfEntity(app);
const selfEntity = usePropertyChange(app, 'selfEntity');
const x = usePropertyChange(selfEntity, 'x', 0, (x) => Math.round(x));
const y = usePropertyChange(selfEntity, 'y', 0, (y) => Math.round(y));
return <div className="self-entity unselectable">

View File

@ -1,18 +0,0 @@
// 3rd party.
import React, {useEffect, useState} from 'react';
export function useSelfEntity(app) {
const [selfEntity, setSelfEntity] = useState();
useEffect(() => {
const onSelfEntityChanged = () => {
const selfEntity = app.selfEntity;
setSelfEntity(selfEntity);
};
onSelfEntityChanged();
app.on('selfEntityChanged', onSelfEntityChanged);
return () => {
app.off('selfEntityChanged', onSelfEntityChanged);
}
}, [selfEntity]);
return selfEntity;
}

View File

@ -6,7 +6,6 @@ import {compose} from '@avocado/core';
import contempo from 'contempo';
// 1st party.
import {usePropertyChange} from '../hooks/use-property-change';
import {useSelfEntity} from '../hooks/use-self-entity';
const decorate = compose(
contempo(`
@ -45,7 +44,7 @@ const decorate = compose(
);
const QuickStatusComponent = ({app}) => {
const selfEntity = useSelfEntity(app);
const selfEntity = usePropertyChange(app, 'selfEntity');
const life = usePropertyChange(selfEntity, 'life', 0);
const maxLife = usePropertyChange(selfEntity, 'maxLife', 0);
const width = life / maxLife;