Skip to content

Commit 3fddd5f

Browse files
committed
pass fromEl and toEl to hook beforeUpdate
Relates to #3615. Allowing beforeUpdate to cancel an update by returning false is **not** implemented, as this would require more complex internal changes.
1 parent 60e7f47 commit 3fddd5f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

assets/js/phoenix_live_view/view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ export default class View {
543543
!fromEl.isEqualNode(toEl) &&
544544
!(isIgnored && isEqualObj(fromEl.dataset, toEl.dataset))
545545
) {
546-
hook.__beforeUpdate();
546+
hook.__beforeUpdate(fromEl, toEl);
547547
return hook;
548548
}
549549
}

assets/js/phoenix_live_view/view_hook.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface HookInterface<E extends HTMLElement = HTMLElement> {
3535
* Called when the element is about to be updated in the DOM.
3636
* Note: any call here must be synchronous as the operation cannot be deferred or cancelled.
3737
*/
38-
beforeUpdate?: () => void;
38+
beforeUpdate?: (fromEl: E, toEl: E) => void;
3939

4040
/**
4141
* The updated callback.
@@ -173,7 +173,7 @@ export interface Hook<T = object, E extends HTMLElement = HTMLElement> {
173173
* Called when the element is about to be updated in the DOM.
174174
* Note: any call here must be synchronous as the operation cannot be deferred or cancelled.
175175
*/
176-
beforeUpdate?: (this: T & HookInterface<E>) => void;
176+
beforeUpdate?: (this: T & HookInterface<E>, fromEl: E, toEl: E) => void;
177177

178178
/**
179179
* The updated callback.
@@ -347,7 +347,7 @@ export class ViewHook<E extends HTMLElement = HTMLElement>
347347

348348
// Default lifecycle methods
349349
mounted(): void {}
350-
beforeUpdate(): void {}
350+
beforeUpdate(_fromEl: E, _toEl: E): void {}
351351
updated(): void {}
352352
destroyed(): void {}
353353
disconnected(): void {}
@@ -364,8 +364,8 @@ export class ViewHook<E extends HTMLElement = HTMLElement>
364364
this.updated();
365365
}
366366
/** @internal */
367-
__beforeUpdate() {
368-
this.beforeUpdate();
367+
__beforeUpdate(fromEl, toEl) {
368+
this.beforeUpdate(fromEl, toEl);
369369
}
370370
/** @internal */
371371
__destroyed() {

0 commit comments

Comments
 (0)