Skip to content

Commit cd0c3bc

Browse files
authoredMar 26, 2024··
fix: refactor nodeOps to return methods at the end of the function (#602)
* fix: refactor nodeOps to return methods at the end of the function * chore: fix lint

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed
 

‎src/core/nodeOps.ts

+27-24
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function invalidateInstance(instance: TresObject) {
3434

3535
export const nodeOps: () => RendererOptions<TresObject, TresObject | null> = () => {
3636
let scene: TresScene | null = null
37-
return { createElement(tag, _isSVG, _anchor, props): TresObject | null {
37+
function createElement(tag, _isSVG, _anchor, props): TresObject | null {
3838
if (!props) props = {}
3939

4040
if (!props.args) {
@@ -92,8 +92,8 @@ export const nodeOps: () => RendererOptions<TresObject, TresObject | null> = ()
9292
}
9393

9494
return instance as TresObject
95-
},
96-
insert(child, parent) {
95+
}
96+
function insert(child, parent) {
9797
if (!child) return
9898

9999
if (parent && parent.isScene) {
@@ -131,8 +131,8 @@ export const nodeOps: () => RendererOptions<TresObject, TresObject | null> = ()
131131
parentObject[child.attach] = child
132132
}
133133
}
134-
},
135-
remove(node) {
134+
}
135+
function remove(node) {
136136
if (!node) return
137137
const ctx = node.__tres
138138
// remove is only called on the node being removed and not on child nodes.
@@ -187,14 +187,14 @@ export const nodeOps: () => RendererOptions<TresObject, TresObject | null> = ()
187187

188188
}
189189

190-
},
191-
patchProp(node, prop, prevValue, nextValue) {
190+
}
191+
function patchProp(node, prop, prevValue, nextValue) {
192192
if (node) {
193193
let root = node
194194
let key = prop
195195
if (node.__tres.primitive && key === 'object' && prevValue !== null) {
196196
// If the prop 'object' is changed, we need to re-instance the object and swap the old one with the new one
197-
const newInstance = nodeOps.createElement('primitive', undefined, undefined, {
197+
const newInstance = createElement('primitive', undefined, undefined, {
198198
object: nextValue,
199199
})
200200
for (const subkey in newInstance) {
@@ -285,23 +285,26 @@ export const nodeOps: () => RendererOptions<TresObject, TresObject | null> = ()
285285

286286
invalidateInstance(node as TresObject)
287287
}
288-
},
288+
}
289289

290-
parentNode(node) {
290+
function parentNode(node) {
291291
return node?.parent || null
292-
},
293-
createText: () => noop('createText'),
294-
createComment: () => noop('createComment'),
295-
296-
setText: () => noop('setText'),
297-
298-
setElementText: () => noop('setElementText'),
299-
nextSibling: () => noop('nextSibling'),
300-
301-
querySelector: () => noop('querySelector'),
302-
303-
setScopeId: () => noop('setScopeId'),
304-
cloneNode: () => noop('cloneNode'),
292+
}
305293

306-
insertStaticContent: () => noop('insertStaticContent') }
294+
return {
295+
insert,
296+
remove,
297+
createElement,
298+
patchProp,
299+
parentNode,
300+
createText: () => noop('createText'),
301+
createComment: () => noop('createComment'),
302+
setText: () => noop('setText'),
303+
setElementText: () => noop('setElementText'),
304+
nextSibling: () => noop('nextSibling'),
305+
querySelector: () => noop('querySelector'),
306+
setScopeId: () => noop('setScopeId'),
307+
cloneNode: () => noop('cloneNode'),
308+
insertStaticContent: () => noop('insertStaticContent'),
309+
}
307310
}

0 commit comments

Comments
 (0)
Please sign in to comment.