fn

runWithApp

v0.1.0testeddemo

Runs a function inside app.runWithContext, so inject (and everything built on it) resolves app-level provides even outside of component setup — in router guards, store actions, event handlers or timers. The app defaults to getActiveApp(); pass one explicitly to target a specific app (recommended for SSR, where apps are created per request).

Example

ts
router.beforeEach(() => {
  const auth = runWithApp(() => inject(AuthKey));
});

Demo

Loading demo…

Signature

ts
export function runWithApp<Result>(fn: () => Result, app: App | undefined = getActiveApp()): Result{ ... }

Type Parameters

Result

Parameters

ParameterTypeDescription
fn() => ResultThe function to run with the app as injection context
app?App | undefinedThe function to run with the app as injection context

Returns

ResultThe return value of fn