pixijs / pixi-react

Write PIXI apps using React declarative style
https://pixijs.io/pixi-react/
MIT License
2.42k stars 180 forks source link

Modularize pixi-react to allow user defined versions of React and PIXI #398

Closed baseten closed 1 year ago

baseten commented 1 year ago

Spec

Rough map of current source to new modules

Notes

Proposed Usage

In a user's app they should setup pixi-react something like this:

import { configurePixiReact } from 'pixi-react';
import { configurePixiReactFiber } from 'pixi-react-fiber-v18';
import { configurePixiReactComponents } from 'pixi-react-components-v7';

export default configurePixiReact({
    configurePixiReactComponents,
    configurePixiReactFiber,
});

Implementation

The configuration function would look something like this:

function configurePixiReact({
    configurePixiReactComponents,
    configurePixiReactFiber,
})
{
    // PixiComponent updates TYPES_INJECTED (or new name since all will be), but this can basically be private and not
    // allow dupes?
    // invariant, PixiComponent, CHILDREN and TYPES_INJECTED come from pixi-react

    // getTextureFromProps also lives inside pixi-react-components even if not exported
    const {
        TYPES,
        createRoot,
        render,
        unmountComponentAtNode,
        Stage,
        applyDefaultProps,
        AppProvider,
        AppConsumer,
        AppContext,
        useTick,
        useApp,
        withPixiApp,
        withFilters,
        eventHandlers,
    } = configurePixiReactComponents({
        invariant,
        PixiComponent,
    });

    // All of the reconciler is basically static, except createElement which depends on TYPES_INJECTED, this configure step
    // basically just makes createElement and then wires everything up
    const PixiFiber = configurePixiReactFiber({
        CHILDREN,
        // updated to include pixi-react-components by configurePixiReactComponents, should we pass this around explicitly?
        TYPES_INJECTED,
        invariant,
        applyDefaultProps,
    });

    return {
        // From pixi-react
        PixiComponent,
        // From pixi-react-components
        TYPES,
        createRoot,
        render,
        unmountComponentAtNode,
        Stage,
        AppProvider,
        AppConsumer,
        AppContext,
        useTick,
        useApp,
        applyDefaultProps,
        // These could come from pixi-react, should they tie to PIXI or React version?
        withPixiApp,
        withFilters,
        eventHandlers,
        // From pixi-react-fiber
        PixiFiber,
    };
}
baseten commented 1 year ago

@Zyie once we release this I think perhaps we should write a note about what we officially support? We can obviously encourage users to write whatever pixi component packages they need for whichever versions of PIXI, but the combinations could get complicated quickly.

So far we've talked about supporting React 17+ and PIXI 6+, does that mean we support:

Combinations could obviously get complex quickly especially as more versions are released in the future.

I'm wondering whether on top of the user injectable API I've proposed above, we should also provide pre-configured pixi-react version(s) packaged as a single module. So for example @pixi/react v8.0.0 becomes a wrapper for the above API including React 18 and PIXI 7?

Zyie commented 1 year ago

@Zyie once we release this I think perhaps we should write a note about what we officially support? We can obviously encourage users to write whatever pixi component packages they need for whichever versions of PIXI, but the combinations could get complicated quickly.

So far we've talked about supporting React 17+ and PIXI 6+, does that mean we support:

  • React 17 + PIXI 6
  • React 18 + PIXI 6
  • React 17 + PIXI 7
  • React 18 + PIXI 7

Yeah i think these should be what we support

So for example @pixi/react v8.0.0 becomes a wrapper for the above API including React 18 and PIXI 7?

Yeah this is a good approach. Makes it very simple for whoever wants the latest version