Skip to content

Commit

Permalink
feat(vue-next): add vue3 css cache
Browse files Browse the repository at this point in the history
  • Loading branch information
zealotchen0 committed May 7, 2024
1 parent 5ef587e commit 3041367
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ export class HippyElement extends HippyNode {
// attributes
public attributes: NativeNodeProps;

// style
// TODO style
public style: NativeNodeProps;

// 包含了 className 解析后的完整属性,待重构
public cssStyle: NativeNodeProps = {};

// events map
public events: NativeNodeProps;

Expand Down Expand Up @@ -874,6 +877,19 @@ export class HippyElement extends HippyNode {
// get styles
let style: NativeNodeProps = this.getNativeStyles();

if (this.parentNode && this.parentNode instanceof HippyElement) {
// 属性继承逻辑实现
// 只继承 color 和 font属性
const parentNodeStyle = this.parentNode.cssStyle;
const styleAttributes = ['color', 'fontSize', 'fontWeight', 'fontFamily', 'fontStyle', 'textAlign', 'lineHeight'];

styleAttributes.forEach((attribute) => {
if (!style[attribute] && parentNodeStyle[attribute]) {
style[attribute] = parentNodeStyle[attribute];
}
});
}

getBeforeRenderToNative()(this, style);

/*
Expand All @@ -892,6 +908,8 @@ export class HippyElement extends HippyNode {
style = { ...updateStyle, ...style };
}

this.cssStyle = style;

const elementExtraAttributes: Partial<NativeNode> = {
name: this.component.name,
props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ export class HippyNode extends HippyEventTarget {
// In the case of keep-alive, the node still exists and will be moved to the virtual container
if (child.parentNode && child.parentNode !== this) {
child.parentNode.removeChild(child);
// TODO keep alive 标记
return;
}

// If the node is already mounted, remove it first, but do not remove when is hydrate.
Expand Down

0 comments on commit 3041367

Please sign in to comment.