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

consider reducer API for updating #33

Open
fergald opened this issue Sep 13, 2022 · 3 comments
Open

consider reducer API for updating #33

fergald opened this issue Sep 13, 2022 · 3 comments
Labels
api Issue with API specs discussion

Comments

@fergald
Copy link
Collaborator

fergald commented Sep 13, 2022

Suggestion from @dominiccooney to consider an API for updating data that is more stream-like. Hopefully this captures it accurately

beacon.updateData(reducer, initialValue)

where reducer(currentValue) returns the new value and if the beacon has already been sent, initialValue is passed in.

Examples:

Replace every time

let newValue = ...;
beacon.updateData(() => {return newValue});

Accumulate data

let diffSinceLastTime = ...;
beacon.updateData((oldValue) => {return oldValue + diffSinceLastTime}, 0);

// cc @nicjansma @cliffcrocker @andydavies @philipwalton @yoavweiss

@philipwalton
Copy link

What about if the API accepted a WritableStream instance?

I'm not sure if that would be possible with this API, but if so, it seems like that could potentially make it more compatible with other streaming use cases.

@mingyc mingyc added discussion api Issue with API specs labels Sep 14, 2022
@mingyc
Copy link
Collaborator

mingyc commented Sep 14, 2022

Some previous related discussion around the API shape: #9 (comment)

@nicjansma
Copy link

This could be useful so the application doesn't need to maintain a duplicate payload state for what it's hoping to send in the beacon.

With today's API shape, if someone wanted to beacon a log of events, they'd need to:

var events = [];

// on new data
events.push({...}); // append to your events list
beacon.setData(events); // replace current beacon payload list with list+1

With updateData you wouldn't need a local (duplicate) copy of the data:

// on new data
beacon.updateData((events) => { return events.push({...}) }, []); // append to existing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue with API specs discussion
Projects
None yet
Development

No branches or pull requests

4 participants