Skip to content

Commit e2f1b79

Browse files
Extract node and grid assignment
Move assignments to the position they are used
1 parent 0a33b8f commit e2f1b79

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/dd-draggable.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,34 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
168168
return coordinates
169169
}
170170

171+
_node() {
172+
return this.el.gridstackNode;
173+
}
174+
175+
_grid() {
176+
return this._node().grid
177+
}
178+
171179
protected _elNewCoordinates(event: KeyboardEvent, element: HTMLElement) {
172-
const node = this.el.gridstackNode
173-
const cellHeight = node.grid.getCellHeight() * node.h
174-
const cellWidth = node.grid.cellWidth()
175-
const maxColumn = node.grid.opts.column
180+
const selectedNode = this._node();
181+
const cellHeight = this._grid().getCellHeight() * selectedNode.h
176182
let xCoord: number, yCoord: number
177183

178184
switch (event.code) {
179185
case 'ArrowRight':
180-
if(typeof(maxColumn) == 'number' && node.x === (maxColumn - 1)) { break }
186+
const maxColumn = this._grid().opts.column
187+
188+
if(typeof(maxColumn) == 'number' && selectedNode.x === (maxColumn - 1)) { break }
181189

182-
xCoord = cellWidth
190+
xCoord = this._grid().cellWidth()
183191
break
184192
case 'ArrowLeft':
185-
if (node.x === 0) { break }
193+
if (selectedNode.x === 0) { break }
186194

187-
xCoord = -cellWidth
195+
xCoord = -this._grid().cellWidth()
188196
break
189197
case 'ArrowUp':
190-
if (node.y === 0) { break }
198+
if (selectedNode.y === 0) { break }
191199

192200
yCoord = -cellHeight
193201
break

0 commit comments

Comments
 (0)