question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[RFC] Add batch API

See original GitHub issue

💬 RFC

🔦 Context

In v2, our binding system becomes synchronous. While there are many benefits, there’ also cons:

  • v1 user surprises: in v1, change notification is handled in next tick, this means user code can have multiple mutation without having to deal with intermediate states.

Consider following example:

class Contact {
  get isComplete() {
    return this.address && this.name && this.phone;
  }
}

If we have a the mutation like this:

function updateContact(contact) {
  contact.address = 'santa'
  contact.name = 'santa'
  contact.phone = 'void';
}

In this example, the changes for the properties address, name and phone are meant to be delivered together.

In v1, change handling is queued, so the isComplete observer will only recompute only once, giving the expected behavior. In v2, change handling is immediate, each mutation is handled by isComplete immediately & synchronously. This, while gives greater amount of control related to timing, sometimes makes it more tedious to handle in cases where there’ multiple consecutive changes that should go together like the above.

A solution for v2, an is common in synchronous binding systems (probably?), is to have a way to batch all the changes notification, and is normally implemented similar to the following form:

function updateContact(contact) {
  contact.address = 'santa'
  contact.name = 'santa'
  contact.phone = 'void'
}

batch(() => {
  updateContact(contact)
})

// or
function updateContact(contact) {
  batch(() => {
    contact.address = 'santa' // not handled
    contact.name = 'santa' // not handled
    contact.phone = 'void' // not handled
  })
  // now handled
}

An example implementation of this is in https://github.com/aurelia/aurelia/pull/1018

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
3cpcommented, Dec 8, 2020

How is the original idea with the flexible $batch.start() $batch.end(), and a simplified @batch decorator in #411?

The start/end API can be replaced by this one, but the @batch decorator could be a nice helper.

0reactions
bigoponcommented, Oct 7, 2022

[…] ease migrations from v1?

@m-gallesio it should be simple to patch some methods on the observers, and we should be able to have roughly the same timing with v1. It’ll be in compat package with the rest we currently have there.

Where did we get on this one?

We got array mutation batching, only need to add back property batching. Should be before beta

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supporting bulk operations in REST APIs - mscharhag
Bulk (or batch) operations are used to perform an action on more than one resource in single request. In this post we will...
Read more >
RFC 7644: System for Cross-domain Identity Management
Bulk requests are identified using the following schema URI: "urn:ietf:params:scim:api:messages:2.0:BulkRequest". Bulk responses are identified using the ...
Read more >
New REST API RFC - Koha Wiki
Guidelines/rules for the new API · POST = create a resource · GET = read a resource · PUT = update a resource...
Read more >
Creating an RFC - AMS Advanced User Guide
Navigate to the Create RFC page: In the left navigation pane of the AMS console click RFCs to open the RFCs list page,...
Read more >
REST API - Bulk Create or Update in single request [closed]
You could also add support for headers in this structure. We implemented something that proved useful which was variables to use between ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found