Skip to content

Support WebGL.Texture like File.File #62

@lydell

Description

@lydell

When using WebGL, you might use WebGL.load to load a texture and store it in the model so you can use it later to render WebGL stuff. However, that type contains a function, which has a few problems:

  • It can’t be transferred correctly from and old app to a new app when migrating during a release. Your new app will crash when it tries to use the texture.
  • There is no compilation error if you put it in ToFrontend and ToBackend msgs, but it can’t be serialized due to the function inside.

The File type from elm/file used to have the same problems, but Lamdera has added support for it. We should do the same for Texture.

  • Support Texture in the wire format using references:

    • -- Frontend only JS reference types
      TType (Module.Canonical (Name "elm" "file") "File") "File" params -> callDecoder "decodeRef" tipe
    • -- Frontend only JS reference types
      TType (Module.Canonical (Name "elm" "file") "File") "File" _ ->
      (a (VarForeign mLamdera_Wire "encodeRef" (Forall Map.empty (TLambda tipe tLamdera_Wire_Encoder))))
    • -- JS types we are supporting through JS ref encodings. These serialisations
      -- CANNOT BE DECODED OUTSIDE OF THE JS SCOPE THEY WERE ENCODED IN!
      TType (Module.Canonical (Name "elm" "file") "File") "File" _ -> False
  • Disallow Texture unless inside FrontendMsg or FrontendModel:

    -- Frontend JS Kernel types
    ("elm", "file", "File", "File") ->
    if targetName `elem` ["FrontendMsg", "FrontendModel"] then
    DKernelBrowser "File.File"
    else
    kernelErrorBrowserOnly

There might be a test case or something that needs updating too.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions