refactor: patcher

This commit is contained in:
cha0s 2021-01-25 23:20:36 -06:00
parent 99163ec1c5
commit bfccfa819a
3 changed files with 8 additions and 8 deletions

View File

@ -31,7 +31,7 @@ const Particle = ({
}) => {
const latus = useLatus();
const entity = useEntity(emitterJson);
const patchParticle = useJsonPatcher(particle, path);
const patch = useJsonPatcher();
const {EntityList} = latus.get('%resources');
const entityList = new EntityList();
const entityListView = new EntityListView(entityList);
@ -57,7 +57,7 @@ const Particle = ({
type="text"
value={particle.rate || 0}
onChange={(event) => {
patchParticle('rate', parseFloat(event.target.value));
patch(path, particle, 'rate', parseFloat(event.target.value));
}}
/>
</label>
@ -67,7 +67,7 @@ const Particle = ({
type="text"
value={particle.count || 1}
onChange={(event) => {
patchParticle('count', parseInt(event.target.value, 10));
patch(path, particle, 'count', parseInt(event.target.value, 10));
}}
/>
</label>

View File

@ -9,7 +9,7 @@ const Existent = ({
json,
path,
}) => {
const patchState = useJsonPatcher(json.state, join(path, 'state'));
const patch = useJsonPatcher();
return (
<div className="existent">
<label>
@ -18,7 +18,7 @@ const Existent = ({
type="checkbox"
checked={json.state.isTicking}
onChange={(event) => {
patchState('isTicking', event.target.checked);
patch(join(path, 'state'), json.state, 'isTicking', event.target.checked);
}}
/>
</label>
@ -28,7 +28,7 @@ const Existent = ({
type="text"
value={json.state.name}
onChange={(event) => {
patchState('name', event.target.value);
patch(join(path, 'state'), json.state, 'name', event.target.value);
}}
/>
</label>

View File

@ -2,11 +2,11 @@ import {useDispatch} from '@latus/redux';
import {useProject, useUri} from '@persea/core';
import {patchJsonResource} from '../state/json';
export default (json, path) => {
export default () => {
const dispatch = useDispatch();
const project = useProject();
const uri = useUri();
return (key, value) => {
return (path, json, key, value) => {
dispatch(patchJsonResource({
patch: [
{