Skip to content

Commit

Permalink
fix: chagne updateItem's accessor prviate to public (#93)
Browse files Browse the repository at this point in the history
* enhance: chagne updateItem's accessor prviate to public

* test: test numeric sizeGroup
  • Loading branch information
daybrush committed May 26, 2023
1 parent ad9b66a commit 5cc145c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
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);
});

});

0 comments on commit 5cc145c

Please sign in to comment.