Skip to content

[WIP] [Live] Make Ajax calls happen in serial, with "queued" changes #466

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

Merged
merged 5 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/LiveComponent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# CHANGELOG

## 2.5.0

- [BEHAVIOR CHANGE] Previously, Ajax calls could happen in parallel (if
you changed a model then triggered an action before the model update Ajax
call finished, the action Ajax call would being in parallel). Now, if
an Ajax call is currently happening, any future requests will wait until
it finishes. Then, all queued changes (potentially multiple model updates
or actions) will be sent all at once on the next request.

## 2.4.0

- [BC BREAK] Previously, the `id` attribute was used with `morphdom` as the
Expand Down
10 changes: 1 addition & 9 deletions src/LiveComponent/assets/src/UnsyncedInputContainer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default class UnsyncedInputContainer {
#mappedFields: Map<string, HTMLElement>;
#unmappedFields: Array<HTMLElement>= [];
#unmappedFields: Array<HTMLElement> = [];

constructor() {
this.#mappedFields = new Map();
Expand All @@ -20,14 +20,6 @@ export default class UnsyncedInputContainer {
return [...this.#unmappedFields, ...this.#mappedFields.values()]
}

clone(): UnsyncedInputContainer {
const container = new UnsyncedInputContainer();
container.#mappedFields = new Map(this.#mappedFields);
container.#unmappedFields = [...this.#unmappedFields];

return container;
}

allMappedFields(): Map<string, HTMLElement> {
return this.#mappedFields;
}
Expand Down
6 changes: 6 additions & 0 deletions src/LiveComponent/assets/src/ValueStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { normalizeModelName } from './string_utils';

export default class {
controller: LiveController;
updatedModels: string[] = [];

constructor(liveController: LiveController) {
this.controller = liveController;
Expand Down Expand Up @@ -33,6 +34,7 @@ export default class {
*/
set(name: string, value: any): void {
const normalizedName = normalizeModelName(name);
this.updatedModels.push(normalizedName);

this.controller.dataValue = setDeepData(this.controller.dataValue, normalizedName, value);
}
Expand All @@ -49,4 +51,8 @@ export default class {
asJson(): string {
return JSON.stringify(this.controller.dataValue);
}

all(): any {
return this.controller.dataValue;
}
}
Loading