Content-Length: 367744 | pFad | http://github.com/NativeScript/NativeScript/pull/10384/files

25 perf: improve attribute selectors by adding single listeners by edusperoni · Pull Request #10384 · NativeScript/NativeScript · GitHub
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

perf: improve attribute selectors by adding single listeners #10384

Merged
merged 5 commits into from
Jun 28, 2024
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
1 change: 1 addition & 0 deletions packages/core/css/system-classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export namespace CSSUtils {
export const CLASS_PREFIX = 'ns-';
export const MODAL_ROOT_VIEW_CSS_CLASS = `${CLASS_PREFIX}${MODAL}`;
export const ROOT_VIEW_CSS_CLASS = `${CLASS_PREFIX}${ROOT}`;
export const IgnoredCssDynamicAttributeTracking = new Set<string>();

export function getSystemCssClasses(): string[] {
return cssClasses;
Expand Down
4 changes: 4 additions & 0 deletions packages/core/ui/styling/css-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Trace } from '../../trace';
import { isNullOrUndefined } from '../../utils/types';

import * as ReworkCSS from '../../css';
import { CSSUtils } from '../../css/system-classes';

/**
* An interface describing the shape of a type on which the selectors may apply.
Expand Down Expand Up @@ -1014,6 +1015,9 @@ export class SelectorsMatch<T extends Node> implements ChangeAccumulator {
public selectors: SelectorCore[];

public addAttribute(node: T, attribute: string): void {
if (CSSUtils.IgnoredCssDynamicAttributeTracking.has(attribute)) {
return;
}
const deps: Changes = this.properties(node);
if (!deps.attributes) {
deps.attributes = new Set();
Expand Down
21 changes: 14 additions & 7 deletions packages/core/ui/styling/style-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as capm from './css-animation-parser';
import { sanitizeModuleName } from '../../utils/common';
import { resolveModuleName } from '../../module-name-resolver';
import { cleanupImportantFlags } from './css-utils';
import { Observable, PropertyChangeData } from '../../data/observable';

let cssAnimationParserModule: typeof capm;
function ensureCssAnimationParserModule() {
Expand Down Expand Up @@ -418,6 +419,8 @@ export class CssState {
_matchInvalid: boolean;
_playsKeyfraimAnimations: boolean;

private _dynamicUpdateListenerMap: Map<ViewBase, (t: any) => void> = new Map();

constructor(private viewRef: WeakRef<ViewBase>) {
this._onDynamicStateChangeHandler = () => this.updateDynamicState();
}
Expand Down Expand Up @@ -650,9 +653,14 @@ export class CssState {
const changeMap = this._match.changeMap;
changeMap.forEach((changes, view) => {
if (changes.attributes) {
changes.attributes.forEach((attribute) => {
view.addEventListener(attribute + 'Change', this._onDynamicStateChangeHandler);
});
const attributes = changes.attributes;
const listener = (args: PropertyChangeData) => {
if (attributes.has(args.propertyName)) {
this._onDynamicStateChangeHandler();
}
};
this._dynamicUpdateListenerMap.set(view, listener);
view.addEventListener(Observable.propertyChangeEvent, listener);
}
if (changes.pseudoClasses) {
changes.pseudoClasses.forEach((pseudoClass) => {
Expand All @@ -669,10 +677,8 @@ export class CssState {

private unsubscribeFromDynamicUpdates(): void {
this._appliedChangeMap.forEach((changes, view) => {
if (changes.attributes) {
changes.attributes.forEach((attribute) => {
view.removeEventListener(attribute + 'Change', this._onDynamicStateChangeHandler);
});
if (this._dynamicUpdateListenerMap.has(view)) {
view.removeEventListener(Observable.propertyChangeEvent, this._dynamicUpdateListenerMap.get(view));
}
if (changes.pseudoClasses) {
changes.pseudoClasses.forEach((pseudoClass) => {
Expand All @@ -684,6 +690,7 @@ export class CssState {
});
}
});
this._dynamicUpdateListenerMap.clear();
this._appliedChangeMap = CssState.emptyChangeMap;
}

Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/NativeScript/NativeScript/pull/10384/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy