Skip to content

Commit

Permalink
avoid creating new object when id is not present
Browse files Browse the repository at this point in the history
  • Loading branch information
LoganDark committed Oct 10, 2021
1 parent 9168c0c commit 42e39dd
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions examples/demo/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,11 @@ function TabStorage({ tab, layout }: { tab: TabNode, layout: FlexLayout.Layout }
}, [scrollDown])

const kickstartingCallback = useCallback((dragging: TabNode | IJsonTabNode) => {
const json = dragging instanceof TabNode ? dragging.toJson() as IJsonTabNode : { id: '#' + v4(), ...dragging }
const json = dragging instanceof TabNode ? dragging.toJson() as IJsonTabNode : dragging

if (json.id === undefined) {
json.id = `#${v4()}`
}

setStoredTabs(tabs => [...tabs, json])

Expand Down Expand Up @@ -565,7 +569,11 @@ function TabStorage({ tab, layout }: { tab: TabNode, layout: FlexLayout.Layout }
const insertionCallback = useCallback((dragging: TabNode | IJsonTabNode, _, __, y: number) => {
const absoluteY = y + tab.getRect().y + layout.getDomRect().top
const { insertionIndex } = calculateInsertion(absoluteY)
const json = dragging instanceof TabNode ? dragging.toJson() as IJsonTabNode : { id: '#' + v4(), ...dragging }
const json = dragging instanceof TabNode ? dragging.toJson() as IJsonTabNode : dragging

if (json.id === undefined) {
json.id = `#${v4()}`
}

setStoredTabs(tabs => {
const newTabs = [...tabs]
Expand Down

0 comments on commit 42e39dd

Please sign in to comment.