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

fix: chagne updateItem's accessor prviate to public #93

Merged
merged 2 commits into from
May 26, 2023
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
2 changes: 1 addition & 1 deletion src/GridItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface GridItemStatus {
mountState?: MOUNT_STATE;
updateState?: UPDATE_STATE;
isFirstUpdate?: boolean;
attributes?: Record<string, string>;
attributes?: Record<string, any>;
orgCSSText?: string;
orgRect?: Required<DOMRect>;
rect?: Required<DOMRect>;
Expand Down
10 changes: 5 additions & 5 deletions src/ItemRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ export class ItemRenderer {
if (updatedItem) {
totalItems.forEach((item) => {
if (items.indexOf(item) === -1) {
this._updateItem(item, true);
this.updateItem(item, true);
}
});
}
}
}
public updateItems(items: GridItem[]) {
items.forEach((item) => {
this._updateItem(item);
this.updateItem(item);
});
}
public getStatus(): ItemRendererStatus {
Expand Down Expand Up @@ -107,7 +107,7 @@ export class ItemRenderer {
this.posPercetage = posPercentage;
this.sizePercetage = sizePercentage;
}
private _updateItem(item: GridItem, checkSizeGroup?: boolean) {
public updateItem(item: GridItem, checkSizeGroup?: boolean) {
const { isEqualSize, isConstantSize, useRoundedSize } = this.options;
const initialRects = this.initialRects;
const { orgRect, element } = item;
Expand All @@ -118,10 +118,10 @@ export class ItemRenderer {
const attributes: Record<string, string> = element
? getDataAttributes(element, this.options.attributePrefix)
: item.attributes;
const sizeGroup = attributes.sizeGroup || "";
const sizeGroup = attributes.sizeGroup ?? "";
const isNotEqualSize = attributes.notEqualSize;

if (sizeGroup && initialRects[sizeGroup]) {
if (sizeGroup !== "" && initialRects[sizeGroup]) {
rect = initialRects[sizeGroup];
} else if (isEqualSize && !isNotEqualSize && !sizeGroup && initialRects[""]) {
rect = initialRects[""];
Expand Down
41 changes: 40 additions & 1 deletion test/unit/ItemRenderer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ describe("test ItemRenderer", () => {
}
});
});

it(`should check get status and restore status`, () => {
// Given
el.style.cssText = "position: absolute; left: 50px; top: 50px; width: 200px; height: 100px;";
Expand Down Expand Up @@ -422,4 +421,44 @@ describe("test ItemRenderer", () => {
"test": "data-grid-test",
});
});
it("should check if width and height are entered by sizeGroup", () => {
// Given
itemRenderer = new ItemRenderer({
horizontal: false,
});

itemRenderer.setStatus({
initialRects: {
"0": {
left: 0,
top: 0,
width: 100,
height: 100,
},
},
});

const item1 = new GridItem(false, {
attributes: {
sizeGroup: 0,
},
});
const item2 = new GridItem(false, {
attributes: {
sizeGroup: 1,
},
});

// When
// update
itemRenderer.updateItem(item1, true);

// not update
itemRenderer.updateItem(item2, true);

// Then
expect(item1.rect.width).to.be.deep.equals(100);
expect(item2.rect.width).to.be.deep.equals(0);
});

});