-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from threlte/invalidation
Return frameInvalidated from advance function
- Loading branch information
Showing
11 changed files
with
149 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@threlte/test': patch | ||
--- | ||
|
||
Return frameInvalidated from advance function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts"> | ||
import { T } from '@threlte/core' | ||
import { interactivity } from '@threlte/extras' | ||
import type { Vector3Tuple } from 'three' | ||
let positions: Vector3Tuple[] = [[0, 0, -1]] | ||
const context = interactivity() | ||
context.raycaster.near = 1 | ||
context.raycaster.far = 10 | ||
const spawnCube = () => { | ||
positions = [...positions, [0, 0, positions.at(-1)?.[2] ?? 0 - 1]] | ||
} | ||
</script> | ||
|
||
{#each positions as position} | ||
<T.Mesh on:click={() => spawnCube()} scale={0.2} {position}> | ||
<T.BoxGeometry /> | ||
</T.Mesh> | ||
{/each} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<script> | ||
import { useTask, useThrelte } from '@threlte/core' | ||
export let autoStart = false | ||
export let autoInvalidate = true | ||
export let prop1 = 0 | ||
export let prop2 = 0 | ||
const { invalidate } = useThrelte() | ||
useTask(() => {}, { autoStart, autoInvalidate }) | ||
$: { | ||
prop1 | ||
} | ||
$: { | ||
prop2 | ||
invalidate() | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, expect, it } from 'vitest' | ||
|
||
import Subject from '../Invalidate.svelte' | ||
import { render } from '../../lib' | ||
|
||
describe('<Invalidate>', () => { | ||
it('does not invalidate on a frozen useTask', () => { | ||
const { advance } = render(Subject) | ||
|
||
const { frameInvalidated } = advance() | ||
|
||
expect(frameInvalidated).toBe(false) | ||
}) | ||
|
||
it('invalidates on a running useTask', () => { | ||
const { advance } = render(Subject, { autoStart: true }) | ||
|
||
const { frameInvalidated } = advance() | ||
|
||
expect(frameInvalidated).toBe(false) | ||
}) | ||
|
||
it('does not invalidate when autoInvalidate is false on a running useTask', () => { | ||
const { advance } = render(Subject, { autoInvalidate: false, autoStart: true }) | ||
|
||
const { frameInvalidated } = advance() | ||
|
||
expect(frameInvalidated).toBe(false) | ||
}) | ||
|
||
// @TODO ongoing discussion | ||
it.skip('does not invalidate when a prop change does not call invalidate()', () => { | ||
const { frameInvalidated } = render(Subject, { prop1: 10 }) | ||
expect(frameInvalidated).toBe(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters