Commit graph

380 commits

Author SHA1 Message Date
Aria Minaei
0a0c35a7b7 Unify Derivation and Prism 5/n 2023-01-04 20:49:44 +01:00
Aria Minaei
a38d96ec95 Unify Derivation and Prism 4/n 2023-01-04 20:49:43 +01:00
Aria Minaei
06808f99e9 Unify Derivation and Prism 3/n 2023-01-04 20:49:43 +01:00
Aria Minaei
bfba1d4879 Unify Derivation and Prism 2/n 2023-01-04 20:49:43 +01:00
Aria Minaei
12b3f477bc Unify Derivation and Prism (1/n) 2023-01-04 20:49:43 +01:00
Aria Minaei
e9bbb0ef41 Remove PrismDerivation.map/flatMap() 2023-01-04 20:49:43 +01:00
Aria Minaei
a073984b2f Mark add/removeDependent() as internal 2023-01-04 20:49:43 +01:00
Aria Minaei
194de8d833 Simplify Derivation.onChange()
It no longer uses `DerivationEmitter`.
2023-01-04 20:49:43 +01:00
Aria Minaei
a24a149a52 Remove Derivation.tapImmediate()
This is now just an extra flag on `Derivation.onChange()`
2023-01-04 20:49:43 +01:00
Aria Minaei
f2bb24ef99 Change the signature of Derivation.changes() to Derivation.onChange()
This way, we no longer expose the `Tappable` interface so we can remove it later.
2023-01-04 20:49:43 +01:00
Aria Minaei
f1cb8edc91 Simplify Derivation.onStale() 2023-01-04 20:49:43 +01:00
Aria Minaei
5c1aa1cd50 Remove Derivation.changesWithoutValues()
And replace it with `Derivation.onStale()`
2023-01-04 20:49:43 +01:00
Aria Minaei
9094e3041e Remove AbstractDerivation
At this point, the only derivation that we have is `PrismDerivation`.
2023-01-04 20:49:43 +01:00
Aria Minaei
63228fd86a Simplify prism.state() 2023-01-04 20:49:43 +01:00
Aria Minaei
ee68112867 Implement prism.source() 2023-01-04 20:49:43 +01:00
Aria Minaei
b117ee0aff Retire DerivationFromSource (1/2)
This is supposed to break the build. In the next commit, I'll implement `HotScope.source()` to fix the build.
2023-01-04 20:49:43 +01:00
Aria Minaei
918dd754a7 Retire ConstantDerivation 2023-01-04 20:49:43 +01:00
Aria Minaei
ed322b66de Separate the hot path from the cold path in prisms 2023-01-04 20:49:43 +01:00
Aria Minaei
c81fe11e52 Rename Prism.changesWithoutValues() to onStale() 2023-01-04 20:49:43 +01:00
Aria Minaei
a71fff0c73 Don't expose PrismDerivation as a class 2023-01-04 20:49:43 +01:00
Aria Minaei
e0a61981c9 Have PrismDerivation no longer extend AbstractDerivation 2023-01-04 20:49:43 +01:00
Aria Minaei
0655e5b1c4 Add performance note about prism scopes 2023-01-04 20:49:43 +01:00
Aria Minaei
83832ef85b Note down that map/flatMap must be removed 2023-01-04 20:49:43 +01:00
Aria Minaei
6d7d461223 Remove all WeakMaps from prism's scope
... making it easier to debug prism scopes. Again, there is a perf regression here.
2023-01-04 20:49:43 +01:00
Aria Minaei
1c69cb7055 Save prism effects in the prism scope, rather than a WeakMap
... for easier debugging, but there is a perf regression which I
can't yet quantify as the benchmark suit doesn't support comparisons.
2023-01-04 20:49:43 +01:00
Aria Minaei
ae8be59366 Implement a basic benchmark test, and deprecate derivation.map()/flatMap()
This starts a new workspace at `packages/benchmarks` where future benchmarks
are going to sit. For now, it only contains a basic profile of a `sequence.play()`
setup.

It also removes all uses of `AbstractDerivation.map()/flatMap()` and uses prisms
instead.
2023-01-04 20:49:35 +01:00
Aria Minaei
45b548660c 0.6.0-dev.3 2023-01-04 20:35:56 +01:00
Aria
718beb4d7b
Catch more SSR issues and improve compat tests (#353)
This will cause the build to fail, as this will catch an SSR issue, which will be fixed after merging #369
2023-01-04 20:03:47 +01:00
Aria
feb3ad34b8
Compact and collapsible compound prop editor
* Create compact vector prop editor

* MAke all compound props collapsible

* Add collapsed indicator for compound props

* Persist collapsed state accross component rerenders

* Adjust dom playground to use the new vector prop

Co-authored-by: Andrew Prifer <andrew.prifer@gmail.com>
2023-01-04 12:43:49 +01:00
Aria Minaei
f6361e7905 0.6.0-dev.2 2023-01-02 22:34:50 +01:00
Aria Minaei
438a83d2d4 0.6.0-dev.1 2023-01-02 19:47:23 +01:00
Aria Minaei
c58bc694ee Fix: Re-render the panels when object identity change
This fixes the pesky "Argument 'der' in 'useDerivation(der)' should not change between renders."
2022-12-31 22:54:52 +01:00
Andrew Prifer
8d8e2348dd Create idb-backed image prop (#366)
Co-authored-by: Clement Roche <rchclement@gmail.com>
2022-12-31 11:01:16 +01:00
Aria Minaei
95b329b02d 0.5.1 2022-12-31 10:54:27 +01:00
Aria Minaei
fcd3ab7ec5 0.5.1-rc.2 2022-12-07 10:24:50 +01:00
Aria Minaei
a9adc2640c 0.5.1-rc.1 2022-11-25 11:21:28 +01:00
Andrew Prifer
e3a194c7dd
Playground improvements (#342)
Remove previews, add vs code task, open in chrome
2022-11-22 15:05:11 +00:00
Andrew Prifer
484cfeb8ba
Add camera playground (#343) 2022-11-22 14:34:15 +00:00
Aria Minaei
a8a9b5ef05 Rename deleteObject() and related params
Since `sheet.deleteObject()` doesn't actually delete the values
of the props of that object, I decided to rename it to `detachObject()`.

Also, the param `override` sounded too similar to the concept of value overrides,
so I renamed it to `reconfigure`.
2022-11-10 16:23:15 +01:00
Andrew Prifer
43714fdf17
Notification improvements (#324) 2022-10-21 20:32:53 +00:00
Andrew Prifer
965d7085dc
Add runtime type checks to r3f (#323)
* Add better error/warning messages to r3f

* Fix notifications playground
2022-10-21 19:17:45 +00:00
Andrew Prifer
62bc12ab51
Create a notification system that can display notifications in Theatre.js' Studio (#320)
* Implement an internal library for studio notifications

* Improve design a little

* Document code

* Change relative import to absolute one

* Fix tiny styling issue

* Add notifications playground

* Add notifications empty state and keep notifications buttons always visible

Also fix a bug related to not clearing the type and uniqueness checkers.

* Simplify notifications playground

* Treat window as optional in case it runs in server code
2022-10-21 15:51:13 +02:00
Aria Minaei
ef5752cbd3 Add a playground for dynamic trees in r3f 2022-10-18 11:43:54 +02:00
Aria Minaei
a9c3c00153 Implement dynamic scene trees in r3f
This makes it possible to add/remove objects on the fly, do hot-module reloading, change object configs on the fly, and more.
2022-10-18 11:43:54 +02:00
Aria Minaei
10c2b69bf3 Implement useExtensionButton() 2022-10-18 11:43:54 +02:00
Andrew Prifer
e708463377
Remove useless TS type (#318) 2022-10-17 14:13:23 +00:00
Andrew Prifer
29e036638b
Normalize theatre keys in r3f (#317)
Also remove a stray console log and make makeStoreKey make more sense.
2022-10-16 16:02:35 +00:00
Andrew Prifer
54ed4c3c41
Improve light support in theatre/r3f (#316)
Add color to all light types and add ambient and hemisphere lights
2022-10-14 13:43:53 +00:00
Andrew Prifer
6497bf2097
Add instant editable cameras to the r3f extension (#315)
Add spruced up editable orthographic/perspective camera
2022-10-13 18:14:53 +00:00
Andrew Prifer
3ec8c20fa6
Warn about (possibly) incorrect custom camera (#308)
Print a warning if people use e.perspectiveCamera or e.orthographicCamera
2022-10-06 14:22:39 +00:00
Aria Minaei
ca9360fc29 Allow audio files in the playground 2022-09-27 23:32:01 +02:00
Aria Minaei
179c7a8158 Allow audio files in the playground 2022-09-27 23:32:01 +02:00
Aria Minaei
6d49e5977c Remove the warning about SSR mode
It's being misunderstood as an error message https://discord.com/channels/870988717190426644/870988717190426647/1020751857024503828
2022-09-27 23:28:23 +02:00
Aria Minaei
87acdbe9ea 0.5.0 2022-09-17 18:54:11 +02:00
Aria Minaei
c97377d868 0.5.0-rc.4 2022-09-17 18:54:11 +02:00
Andrew Prifer
743254a6c6
Fix popover behavior when popover is open and the trigger is clicked (#211)
* Fix popover behavior when open and clicking on trigger

* Remove console log

* Resolve merge conflicts

* Remove destructuring in favor of property access

* Extract usePopover return type into an interface

* Fix merge
2022-09-14 09:05:09 -04:00
Andrew Prifer
8680f9d89e
Replace uniqueName with theatreKey (#285) 2022-09-14 08:36:49 -04:00
Elliot
735bd983a5
Fix/0.5-compatability-tests (#293)
* Working changes

* Fix window undefined bug by updating lib

* Fix TransformControlsImpl import

* Fix compatibility tests>simple debuggable examples
2022-09-13 15:37:39 -04:00
Andrew Prifer
494c60d0c3
Require Opt modifier for orbiting (#286) 2022-08-25 19:55:47 +02:00
Elliot
a871aa628f Revert "Handle requestPointerLock error cases in iframes P-199 (#272)"
This reverts commit 2ef9d5e346.
2022-08-17 16:14:36 -04:00
Andrew Prifer
14603bccbd
Make transform controls only update the props that are being manipulated in the current mode of the transform controls (#279)
Only update the transform that is being manipulated in the current mode
2022-08-15 15:15:37 +00:00
Cole Lawrence
e0c9626d68 dev: Add "reading obj value" playground test 2022-08-05 10:30:13 -04:00
Cole Lawrence
c00144464d dev: Fix playground scroll y on home page 2022-08-05 10:30:13 -04:00
vezwork
fdf268ad43 Add comments and remove extra performance measure
Co-authored-by: Cole Lawrence <cole@colelawrence.com>
2022-08-04 13:34:08 -04:00
Cole Lawrence
62def1e883 Add r3f stress + Ticker.__ticks counter 2022-08-04 13:34:08 -04:00
Cole Lawrence
ea3e7434c6 Fix e2e visual regression tests by always showing Updates badge in CI
- ensure that window.__IS_VISUAL_REGRESSION_TESTING is true when CI=1
2022-08-03 11:38:44 -04:00
Cole Lawrence
963b03ab6e dev: Add warning for unbound .tick() call 2022-08-03 11:38:44 -04:00
Cole Lawrence
63056c5a58 fix validate path call (warning) & playground dom: Fix namespace warning 2022-08-03 11:38:44 -04:00
Cole Lawrence
2ef9d5e346
Handle requestPointerLock error cases in iframes P-199 (#272)
See https://linear.app/theatre/issue/P-199/dont-use-pointer-lock-when-in-an-iframe
2022-08-03 13:55:09 +00:00
Cole Lawrence
8bd37a28d6 r3f fix: Pinching creates more than one undo level in r3f P-202
See https://linear.app/theatre/issue/P-202/pinching-creates-more-than-one-undo-level-in-r3f-history-bug
2022-08-02 16:06:15 -04:00
Fülöp Kovács
e3226da492 Add namespacing to dom example 2022-07-26 10:43:36 +01:00
Cole Lawrence
fcc23b3863 Add variants of the extension example 2022-07-25 12:01:26 -04:00
Cole Lawrence
984a61347f Use "Theatre.js" for name consistency
Co-authored-by: Fülöp <fulopkovacs@users.noreply.github.com>
2022-07-25 12:01:26 -04:00
Cole Lawrence
58f04685ad r3f: Accept function for objRef like for setState 2022-07-25 12:01:26 -04:00
Cole Lawrence
415e493834 doc: Add doc to Ticker.raf 2022-07-25 12:01:26 -04:00
Cole Lawrence
a48155f8dc r3f readme: Update with corrected API 2022-07-25 12:01:26 -04:00
Cole Lawrence
5ca3edead8 dev: Fix r3f tsconfig to include TSX files 2022-07-25 12:01:26 -04:00
Cole Lawrence
11b5d175f4
Fix github checks (#263)
* Update dependencies which pass tests locally

* Break the yarn cache in an attempt to fix checks

* playground: Add wrapping error info for build.ts

* playground: Don't use dev mode in CI tests

* playground: Use tsc for typecheck

* playground: Specify working esbuild version 0.13.15

* playground: Use only promises in build.ts

* playground: Ensure serving in ci e2e

 * Add echo for vercel for build:static
2022-07-25 10:37:34 +02:00
Aria Minaei
a8176a36f7 0.5.0-rc.3 2022-07-12 18:37:04 +02:00
Aria Minaei
00a039a713 Fix exports of @theatre/r3f so it is consistently interpreted across bundlers
Before this commit, the exports field of `@theatre/r3f` was:

```
"exports": {
  ".": "./dist/index.js",
  "./extension": "./dist/extension/index.js"
 },
 ```
So users could import the extension from '@theatre/r3f/extension'

However, if the user’s bundler doesn’t support the exports field, they’d have to import from @theatre/r3f/dist/extension. There are 3 problems with this approach:

1. We have to ask users to try both paths and see which works for their bundler.
2. Users can’t copy code from each other if their bundler setups are different.
3. To make matters worse, if a user’s bundler supports exports, they can’t import from @theatre/r3f/dist/extension.

This is all confusing, so we're fixing it by exposing @theatrer/3f/dist/extension and not @theatre/r3f/extension. Uglier, but more consistent, and avoids the above 3 problems.
2022-07-12 17:49:09 +02:00
Aria Minaei
667f9d4fa2 Massive perf-gain in @theatre/react
Remove cold derivation reads

Prior to this commit, the first render of every `useDerivation()` resulted in a cold read of its inner derivation. Cold reads are predictably slow. The reason we'd run cold reads was to comply with react's rule of not running side-effects during render. (Turning a derivation hot is _technically_ a side-effect).

However, now that users are animating scenes with hundreds of objects in the same sequence, the lag started to be noticable.

This commit changes `useDerivation()` so that it turns its derivation hot before rendering them.

Freshen derivations before render

Previously in order to avoid the zombie child problem (https://kaihao.dev/posts/stale-props-and-zombie-children-in-redux) we deferred freshening the derivations to the render phase of components. This meant that if a derivation's dependencies changed, `useDerivation()` would schedule a re-render, regardless of whether that change actually affected the derivation's value. Here is a contrived example:

```
const num = new Box(1)
const isPositiveD = prism(() => num.derivation.getValue() >= 0)

const Comp = () => {
  return <div>{useDerivation(isPositiveD)}</div>
}

num.set(2) // would cause Comp to re-render- even though 1 is still a positive number
```

We now avoid this problem by freshening the derivation (i.e. calling `der.getValue()`) inside `runQueue()`, and then only causing a re-render if the derivation's value is actually changed.

This still avoids the zombie-child problem because `runQueue` reads the derivations in-order of their position in  the mounting tree.

On the off-chance that one of them still turns out to be a zombile child, `runQueue` will defer that particular `useDerivation()` to be read inside a normal react render phase.
2022-07-12 13:34:29 +02:00
Aria Minaei
cbfc8861b5 Add comment about bundling deps in r3f/extension 2022-07-08 14:08:57 +02:00
Aria Minaei
0631d02d31 0.5.0-rc.2 2022-07-07 22:34:51 +02:00
Aria Minaei
8d977ed6ba Don't minify @theatre/r3f/dist/extension.js 2022-07-07 22:34:51 +02:00
Aria Minaei
158923b376 Upgrade playwright and percy 2022-07-07 16:36:12 +02:00
Aria Minaei
d2ef25f8d4 Quick hack to fix the randomly breaking e2e tests 2022-07-07 16:36:12 +02:00
Aria
a9910fecba
Unsuppress useful warnings in core. (#248)
This also temporarily removes `coreLogger`'s config from the public API One reason is that we don't have many logs that could benefit from suppressing (see diff) so the experimental API would not be useful to the user yet.

Also, the default config was suppressing useful warnings. Those warnings _would_ have been dead-code-eliminated in production mode anyway, so having a separate config to suppress them in dev mode makes it confusing.

Fixes P-171
2022-07-07 10:27:21 +02:00
Andrew Prifer
d1ef903355
Enable hiding the reference window (#241) 2022-06-29 15:06:24 +00:00
Andrew Prifer
2b8a1e3ed1
Fix playground live reload multiplying connections on error in Chrome and Safari (#238) 2022-06-28 22:17:37 +02:00
Andrew Prifer
a3d9892841
Relax editable TS types to allow creating editable versions of all the JSX.IntrinsicElements elements. (#237)
Enable custom editable components through relaxed typescript types
2022-06-28 16:11:28 +00:00
Andrew Prifer
b98c5d86b6
Fix editable TS (#235)
Fix primitive not being supported by the typings
2022-06-28 15:06:55 +00:00
Elliot
006121da91
Fix extension buttons spacing, add extension example (#229)
* Fix extension buttons spacing & styles
* Refactor extension button styles
* Clean up extension prism
2022-06-26 16:00:59 +00:00
Elliot
2854881e17
Add support for passing scalars to vector props (#228)
Co-authored-by: Andrew Prifer <AndrewPrifer@users.noreply.github.com>
2022-06-26 15:47:20 +00:00
Cole Lawrence
7b337a9731 doc(playground dev): Live reload README.md
Co-authored-by: Elliot <key.draw@gmail.com>
2022-06-24 09:52:56 -04:00
Cole Lawrence
df05be3c1e dev playground: Remove mention and dependency on vite 2022-06-24 09:52:56 -04:00
Cole Lawrence
2a93aa3cdc dev playground: Watch and rewrite custom index.html files 2022-06-24 09:52:56 -04:00
Cole Lawrence
aa60556046 dev: Playground "dom" offsets new boxes 2022-06-24 09:52:56 -04:00
Cole Lawrence
f70eea1c48 dev: Playground enable custom html landing page 2022-06-24 09:52:56 -04:00
Cole Lawrence
6dc68d9ae9 fix playground navigation by disabling live-reload for iframed 2022-06-22 14:58:15 -04:00
Cole Lawrence
92921734e9 docs: Remove redundant doc comment 2022-06-22 14:58:15 -04:00