Skip to content

Commit

Permalink
wip: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dxinteractive committed Feb 17, 2020
1 parent 43f9539 commit fb227df
Show file tree
Hide file tree
Showing 15 changed files with 139 additions and 1,444 deletions.
4 changes: 2 additions & 2 deletions packages/dataparcels/.size-limit.json
Expand Up @@ -24,11 +24,11 @@
"path": "ParcelNode.js"
},
{
"limit": "5.9 KB",
"limit": "6.0 KB",
"path": "asNode.js"
},
{
"limit": "6.2 KB",
"limit": "6.3 KB",
"path": "asChildNodes.js"
},
{
Expand Down
21 changes: 13 additions & 8 deletions packages/dataparcels/src/modifiers/translate.js
@@ -1,12 +1,12 @@
// @flow
import type Parcel from '../parcel/Parcel';
import type ChangeRequest from '../change/ChangeRequest';

import asNode from '../parcelNode/asNode';
import update from 'unmutable/lib/update';

type Config = {
down?: (value: any) => any,
up?: (value: any, changeRequest: ChangeRequest) => any,
down?: (parcelData: any) => any,
up?: (parcelData: any) => any,
preserveInput?: boolean
};

Expand All @@ -17,26 +17,31 @@ export default (config: Config) => {
preserveInput
} = config;

let downValue = update('value', down);
let upValue = update('value', up);

if(!preserveInput) {
return (parcel: Parcel): Parcel => parcel
.modifyDown(down)
.modifyUp(up);
.modifyDown(downValue)
.modifyUp(upValue);
}

return (parcel: Parcel): Parcel => parcel
.modifyDown(asNode(node => {
if('translated' in node.meta) {
return node.update(() => node.meta.translated);
return node.update(() => ({
value: node.meta.translated
}));
}

return node
.update(down)
.update(downValue)
.setMeta({
untranslated: node.value
});
}))
.modifyUp(asNode((node) => {
let updated = node.update(up);
let updated = node.update(upValue);

return updated
.setMeta({
Expand Down
18 changes: 4 additions & 14 deletions packages/dataparcels/src/parcel/Parcel.js
Expand Up @@ -15,7 +15,6 @@ import type {ParentType} from '../types/Types';

import {ParcelTypeMethodMismatch} from '../errors/Errors';

import cancel from '../change/cancel';
import ChangeRequest from '../change/ChangeRequest';
import Action from '../change/Action';

Expand Down Expand Up @@ -329,7 +328,7 @@ export default class Parcel {

// Types(`update()`, `updater`, `function`)(updater);
this.update = (updater: ParcelValueUpdater) => {
fireAction('setData', prepUpdater(updater)(this._parcelData));
fireAction('setData', prepUpdater(updater, this._parcelData));
};

this.delete = () => fireActionOnlyType(Child, 'delete');
Expand Down Expand Up @@ -373,32 +372,23 @@ export default class Parcel {

// Types(`modifyDown()`, `updater`, `function`)(updater);
this.modifyDown = (updater: ParcelValueUpdater): Parcel => {
let parcelDataUpdater = prepUpdater(updater);
return this._create({
rawId: this._idPushModifierUpdater('md', updater),
parcelData: parcelDataUpdater(this._parcelData),
parcelData: prepUpdater(updater, this._parcelData),
updateChangeRequestOnDispatch: (changeRequest) => changeRequest._addStep({
type: 'md',
updater: parcelDataUpdater
updater: parcelData => prepUpdater(updater, parcelData)
})
});
};

// Types(`modifyUp()`, `updater`, `function`)(updater);
this.modifyUp = (updater: ParcelValueUpdater): Parcel => {
let parcelDataUpdater = (parcelData: ParcelData, changeRequest: ChangeRequest): ParcelData => {
let nextData = prepUpdater(updater)(parcelData, changeRequest);
if(nextData.value === cancel) {
throw new Error('CANCEL');
}
return nextData;
};

return this._create({
rawId: this._idPushModifierUpdater('mu', updater),
updateChangeRequestOnDispatch: (changeRequest) => changeRequest._addStep({
type: 'mu',
updater: parcelDataUpdater,
updater: (parcelData, changeRequest) => prepUpdater(updater, parcelData, changeRequest),
changeRequest
})
});
Expand Down

0 comments on commit fb227df

Please sign in to comment.