Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/async modifyup #291

Merged
merged 6 commits into from Apr 3, 2020
Merged

Conversation

dxinteractive
Copy link
Collaborator

@dxinteractive dxinteractive commented Apr 3, 2020

Addresses #280

dataparcels

  • Amend: Some changes to translate's API
  • Add: modifyUp() can now return an effect that can be used to trigger one or more async changes in response to a change. They are called after the initial triggering change has taken place, similar to how React's useEffect is called after render. They can produce any number of changes by calling the update function, which works just like parcel.update(). This makes them compatible with callbacks, promises and observables.

This will allow for heaps of code reduction in the library, as all internal async await based code can be re-written to use this instead.

Example of some async validation being written to some meta data.

parcel.modifyUp(({value}) => ({
    meta: {
        message: "Validating, please wait"
    },
    effect: async (update) => {
        let isValid = await validationRequest(value);
        update(() => ({
            meta: {
                message: isValid ? "Valid" : "Not valid"
            }
        }));
    }    
}));

parcel.update(effectUpdater);
}
delete _treeShare.effectRegistry[effectId];
}, 100);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's up with this set timeout? seems like a magic number.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is yeah, but its essentially a throttle / debounce. It's quite like how React has a small delay / buffer to allow very fast subsequent changes to state to be treated as the same state update. I need to bucket all effect calls together to be able to dedupe them, as the thing that calls the effect function can be called multiple times as a change goes up through all the parcels. But I also have no way of knowing when the change is complete and I can stop buffering, because the parcels are all a bit decentralised, there is no god parcel that can say when a round of buffering should stop.

@dxinteractive dxinteractive merged commit 6841a5b into release/strict-swift Apr 3, 2020
@dxinteractive dxinteractive deleted the feature/async-modifyup branch April 3, 2020 03:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants