Re-do bundling, compat tests, and extension API (#174)

This commit is contained in:
Aria 2022-05-25 00:37:18 +02:00 committed by GitHub
parent 5ee9a2543f
commit ec18687a98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
83 changed files with 1138 additions and 886 deletions

View file

@ -1,9 +1,7 @@
import * as path from 'path'
import {build} from 'esbuild'
const definedGlobals = {
global: 'window',
}
const definedGlobals = {}
function createBundles(watch: boolean) {
const pathToPackage = path.join(__dirname, '../')

View file

@ -1,10 +1,42 @@
type ICallback = (t: number) => void
function createRafTicker() {
const ticker = new Ticker()
if (typeof window !== 'undefined') {
/**
* @remarks
* TODO users should also be able to define their own ticker.
*/
const onAnimationFrame = (t: number) => {
ticker.tick(t)
window.requestAnimationFrame(onAnimationFrame)
}
window.requestAnimationFrame(onAnimationFrame)
} else {
ticker.tick(0)
setTimeout(() => ticker.tick(1), 0)
console.log(
`@theatre/dataverse is running in a server rather than in a browser. We haven't gotten around to testing server-side rendering, so if something is working in the browser but not on the server, please file a bug: https://github.com/theatre-js/theatre/issues/new`,
)
}
return ticker
}
let rafTicker: undefined | Ticker
/**
* The Ticker class helps schedule callbacks. Scheduled callbacks are executed per tick. Ticks can be triggered by an
* external scheduling strategy, e.g. a raf.
*/
export default class Ticker {
static get raf(): Ticker {
if (!rafTicker) {
rafTicker = createRafTicker()
}
return rafTicker
}
private _scheduledForThisOrNextTick: Set<ICallback>
private _scheduledForNextTick: Set<ICallback>
private _timeAtCurrentTick: number

View file

@ -62,10 +62,16 @@ function createMechanism() {
function getSharedMechanism(): ReturnType<typeof createMechanism> {
const varName = '__dataverse_discoveryMechanism_sharedStack'
if (global) {
const root =
typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {}
if (root) {
const existingMechanism: ReturnType<typeof createMechanism> | undefined =
// @ts-ignore ignore
global[varName]
root[varName]
if (
existingMechanism &&
typeof existingMechanism === 'object' &&
@ -75,7 +81,7 @@ function getSharedMechanism(): ReturnType<typeof createMechanism> {
} else {
const mechanism = createMechanism()
// @ts-ignore ignore
global[varName] = mechanism
root[varName] = mechanism
return mechanism
}
} else {