@threlte/core
Advanced tools
Comparing version 8.0.0-next.25 to 8.0.0-next.26
import type { Snippet } from 'svelte'; | ||
import type { Object3D } from 'three'; | ||
import type { DisposableObject } from '../../context/fragments/disposal'; | ||
/** Inlined from type-fest */ | ||
@@ -44,3 +45,3 @@ type ConditionalKeys<Base, Condition> = { | ||
*/ | ||
export type DisposableProps = { | ||
export type DisposableProps<Type> = MaybeInstance<Type> extends DisposableObject ? { | ||
/** | ||
@@ -50,2 +51,4 @@ * If true, the object will be deeply disposed when the component unmounts. | ||
dispose?: boolean; | ||
} : { | ||
dispose?: never; | ||
}; | ||
@@ -57,3 +60,5 @@ /** | ||
args?: any[] | ConstructorParameters<Type>; | ||
} : Record<string, unknown>; | ||
} : { | ||
args?: never; | ||
}; | ||
export type RefProps<Type> = { | ||
@@ -72,3 +77,3 @@ ref?: MaybeInstance<Type>; | ||
* camera, set this to true. | ||
* @default true | ||
* @default false | ||
*/ | ||
@@ -81,3 +86,6 @@ manual?: boolean; | ||
makeDefault?: boolean; | ||
} : Record<string, unknown>; | ||
} : { | ||
makeDefault?: never; | ||
manual?: never; | ||
}; | ||
/** | ||
@@ -117,3 +125,3 @@ * ### Instance Props | ||
ref: MaybeInstance<Type>; | ||
}]> = AnyProps & DisposableProps & RefProps<Type> & BaseProps<Type, ChildrenArgs> & ClassProps<Type> & CameraProps<Type> & InstanceProps<Type> & EventProps<Type>; | ||
}]> = AnyProps & DisposableProps<Type> & RefProps<Type> & BaseProps<Type, ChildrenArgs> & ClassProps<Type> & CameraProps<Type> & InstanceProps<Type> & EventProps<Type>; | ||
/** | ||
@@ -120,0 +128,0 @@ * ### `TProps<Type>` |
import { getContext, onDestroy, setContext } from 'svelte'; | ||
import { derived, get, writable } from 'svelte/store'; | ||
import { useDisposal } from '../../../context/fragments/disposal'; | ||
import { watch } from '../../../utilities'; | ||
import { isInstanceOf, watch } from '../../../utilities'; | ||
const contextName = Symbol('threlte-disposable-object-context'); | ||
@@ -12,7 +12,3 @@ /** | ||
const isDisposableObject = (object) => { | ||
return (typeof object === 'object' && | ||
object !== null && | ||
'dispose' in object && | ||
typeof object.dispose === 'function' && | ||
!('isScene' in object)); | ||
return typeof object?.dispose === 'function' && !isInstanceOf(object, 'Scene'); | ||
}; | ||
@@ -19,0 +15,0 @@ export const useDispose = (dispose) => { |
@@ -1,5 +0,4 @@ | ||
export type DisposableThreeObject = { | ||
dispose?: () => void; | ||
type?: string; | ||
} & Record<string, unknown>; | ||
export type DisposableObject = { | ||
dispose: () => void; | ||
}; | ||
export type DisposalContext = { | ||
@@ -13,10 +12,10 @@ /** | ||
* effectivly incrementing the mount count. */ | ||
disposableObjectMounted: (object: DisposableThreeObject) => void; | ||
disposableObjectMounted: (object: DisposableObject) => void; | ||
/** Mark an object as unmounted, effectivly decrementing the mount count. If | ||
* the mount count is 0, the object will be disposed. */ | ||
disposableObjectUnmounted: (object: DisposableThreeObject) => void; | ||
disposableObjectUnmounted: (object: DisposableObject) => void; | ||
/** Remove an object from the disposal context */ | ||
removeObjectFromDisposal: (object: DisposableThreeObject) => void; | ||
removeObjectFromDisposal: (object: DisposableObject) => void; | ||
/** Objects that *can* be disposed */ | ||
disposableObjects: Map<DisposableThreeObject, number>; | ||
disposableObjects: Map<DisposableObject, number>; | ||
shouldDispose: boolean; | ||
@@ -23,0 +22,0 @@ }; |
@@ -24,3 +24,2 @@ export declare const VERSION = 8; | ||
export { createSchedulerContext, useScheduler } from './context/fragments/scheduler.svelte'; | ||
export type { Size } from './types'; | ||
export * from './utilities'; |
@@ -18,3 +18,3 @@ /** | ||
export const isInstanceOf = (obj, type) => { | ||
return typeof obj === 'object' && obj !== null && !!obj[`is${type}`]; | ||
return obj?.[`is${type}`] === true; | ||
}; |
{ | ||
"name": "@threlte/core", | ||
"version": "8.0.0-next.25", | ||
"version": "8.0.0-next.26", | ||
"author": "Grischa Erbe <hello@legrisch.com> (https://legrisch.com)", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
158475
99
4103