Skip to content

Replace component context with with / provide. - #843

Draft
gdotdesign wants to merge 5 commits into
masterfrom
with-provide
Draft

gdotdesign wants to merge 5 commits into
masterfrom
with-provide

Conversation

@gdotdesign

Copy link
Copy Markdown
Member

Replace component context with with / provide

Adds dependency injection that is checked at compile time. It replaces the component context / provide members (breaking).

module Api {
  fun get (path : String) : String {
    with config : Config {
      config.baseUrl + path
    }
  }
}

component Main {
  fun render : Html {
    provide { config: { baseUrl: "https://example.com" } } {
      <div>Api.get("/users")</div>
    }
  }
}

How it works

  • with name : Type { ... } reads a value in any function. with name : Type as a component member reads it in the whole component.
  • provide { name: value, ... } { ... } provides values to everything called or rendered inside it.
  • Values are matched by name and passed as hidden parameters and props at compile time. There is no runtime context.
  • Everything is checked at compile time:
    • Reading a value that nothing provides is an error (there are no defaults).
    • Providing a value that nothing reads is an error.
    • Providing a value with the wrong type is an error.
  • A component can provide values to the content between its tags (children and other Html properties).

Rules

  • Re-providing: a value can be provided again around code that already reads it (e.g. a wrapped logger). Reading the outer with inside that new provide is an error (with_shadowed).
  • Refs: ref.fn() uses the component's own values unless a value is provided around the call. A value of a different type there is an error.
  • Constants and states: constants follow the provided values, including through other constants, functions and gets. States only take their initial value from them.

Also in this PR

  • Parser: the operands of |> now get the pipe as their parent. Before, a with read inside a pipe was reported as not provided.
  • Exposed object: the object a component exposes through a ref is now created once and refreshed on every render, so its members always see the current values. This changes the compiled output of every component accessed through a ref.
  • Tooling: the language server hover and the generated docs list what each function, get and component needs. Formatter and completion support is included.
  • Removed: context members, the provide component member, context defaults on types, and createContext / useContext from the runtime.

@gdotdesign
gdotdesign requested a review from Sija November 23, 2026 18:06
@gdotdesign gdotdesign self-assigned this Nov 23, 2026
@gdotdesign
gdotdesign removed the request for review from Sija November 27, 2026 14:02
@gdotdesign
gdotdesign marked this pull request as draft November 27, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant