Re-do bundling, compat tests, and extension API (#174)
This commit is contained in:
parent
5ee9a2543f
commit
ec18687a98
83 changed files with 1138 additions and 886 deletions
|
@ -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, '../')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue