nodeOpsUtils.ts 826 B

1234567891011121314151617181920212223242526272829303132
  1. import type { TresContext } from '../composables/useTresContextProvider'
  2. import type { LocalState, TresInstance, TresObject } from '../types'
  3. export function prepareTresInstance<T extends TresObject>(obj: T, state: Partial<LocalState>, context: TresContext): TresInstance {
  4. const instance = obj as unknown as TresInstance
  5. instance.__tres = {
  6. type: 'unknown',
  7. eventCount: 0,
  8. root: context,
  9. handlers: {},
  10. memoizedProps: {},
  11. objects: [],
  12. parent: null,
  13. ...state,
  14. }
  15. return instance
  16. }
  17. export function invalidateInstance(instance: TresObject) {
  18. const ctx = instance?.__tres?.root
  19. if (!ctx) { return }
  20. if (ctx.render && ctx.render.canBeInvalidated.value) {
  21. ctx.invalidate()
  22. }
  23. }
  24. export function noop(fn: string): any {
  25. // eslint-disable-next-line no-unused-expressions
  26. fn
  27. }