Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene inputs #11

Open
pschiffmann opened this issue Jul 13, 2023 · 0 comments
Open

Scene inputs #11

pschiffmann opened this issue Jul 13, 2023 · 0 comments
Labels
scene-document SceneDocument, NodeData, Expression

Comments

@pschiffmann
Copy link
Owner

At the moment, generated scene components can't have props. This means that all external state must be passed into the scene through React context, then unpacked and exposed as outputs by BLoC components that are placed at the root of the scene node tree.

Instead, it should be possible to declare scene inputs inside of a scene. Scene inputs are serialized and stored inside the scene.json file, like this:

{
  "sceneInputs": {
    "colorScheme": {
      "type": {
        "type": "union",
        "elements": [
          {
            "type": "string",
            "value": "light"
          },
          {
            "type": "string",
            "value": "dark"
          }
        ]
      },
      "stageValue": {
        "type": "string-literal",
        "value": "light"
      }
    },
    "translate": {
      "type": {
        "type": "function",
        "parameters": [
          {
            "type": "string"
          }
        ],
        "returns": {
          "type": "string"
        }
      },
      "stageValue": {
        "type": "stage-prop",
        "prop": "translate"
      }
    }
  },
  "rootNode": "MyBloc",
  "nodes": {
    ...
  }
}

The generated scene.tsx file will contain the following code:

export interface MySceneProps {
  colorScheme: "light" | "dark";
  translate: (p1: string) => string;
}

export function MyScene({ colorScheme, translate }: MySceneProps) {
  ...
}

For the production scene.tsx code, the scene input values can be provided by the user when the scene component is rendered. Inside the stage, that doesn't work. Instead, the user must be able to assign values to the scene inputs through the editor UI. The editor UI changes are out of scope of this issue, and will be covered in a separate issue. But this issue needs to lay the foundation by implementing a mechanism where the stage runtime evaluates Expressions and passes the values to the scene inputs. The expressions are persisted in the stageValue key of scene.json.

@pschiffmann pschiffmann added the scene-document SceneDocument, NodeData, Expression label Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scene-document SceneDocument, NodeData, Expression
Projects
Development

No branches or pull requests

1 participant