npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@leanjs/vue

v0.9.2

Published

Create your own Vue bindings for LeanJS Runtime

Downloads

14

Readme

@leanjs/vue

Installation

If your Vue app is in a monorepo (recommended) execute the following command at the root of your repository:

yarn add -W @leanjs/vue @leanjs/core @leanjs/vue-router

then in the package.json of your Vue app add the following peerDependencies:

"peerDependencies": {
  "@leanjs/core": "*",
  "@leanjs/vue": "*",
  @leanjs/vue-router: "*"
}

If your Vue app is not in a monorepo, then run the following command instead of the above:

yarn add @leanjs/vue @leanjs/core @leanjs/vue-router

Basic usage

createRuntimeBindings

1 . First, you have to create your Vue bindings for your runtime.

// shared-runtime.ts

// You need to configure your runtime
const defaultState = { locale: "en" }; // this is just an example
export const { createRuntime } = configureRuntime(defaultState)({
  onError: () => {},
});

// Then create your Vue bindings for your runtime
export const { useSharedState, HostProvider } =
  createRuntimeBindings(createRuntime);

:::info

Read @leanjs/core if you have not already created your own createRuntime function

:::

2 . Add a HostProvider to the root of your app tree

<template>
  <div>
    <h1>Nuxt Host</h1>
    <HostProvider :runtime="runtime" origin="http://localhost:56500">
      <NuxtPage />
    </HostProvider>
  </div>
</template>

<script setup lang="ts">
  import { createRuntime, HostProvider } from "./runtime-vue";

  const runtime = createRuntime({ context: { appName: "VueShell" } });
</script>

3 . Use your useSharedState in your app, e.g.

<template>
  <h1>Locale is {{ locale }}</h1>
</template>
<script>
  import { useSharedState } from "./runtime-vue";
  export default {
    name: "App",
    setup() {
      return useSharedState("locale");
    },
  };
</script>

useSharedState

Composable to get the current state of one or many shared state properties. Types:

type useSharedState = <
  MyState extends Record<string, any>,
  Prop extends keyof MyState
>(
  ...props:
    | Prop[]
    | {
        prop: Prop;
        loader?: () => MyState[Prop] | Promise<MyState[Prop]>;
        deep?: boolean;
      }
) => Record<Prop, Ref<MyState[Prop]>>;

ComposableApps

To use any of the following composables, you must first call createRuntimeBindings. Read the basic usage section above for more info.

createApp

Arguments:

  • App: Component - required
  • options: { appName: string } - required.

Create a file called index.ts|js in the src directory where your composable app is. For example: Create a file called index.ts|js in the src directory where your composable app is. For example:

my-monorepo/
├- apps/
│  ├─ vue-host/
├─ composable-apps/
│  ├─ vue-app-1/
│  │  ├─ package.json
│  │  ├─ src/
│  │  │  ├─ VueApp1.vue
│  │  │  ├─ index.ts 👈
├─ package.json

:::tip

Read the recommended setup in our getting started page if you want to create a similar monorepo structure

:::

Call createApp with the root component of your app, for example:

// my-monorepo/composable-apps/vue-app-1/src/index.ts
import { createApp } from "@leanjs/vue-router";

import RemoteVue1 from "./RemoteVue1.vue";

export default createApp(RemoteVue1, { appName: "RemoteVue1" });

Hello world example of the RemoteVue1 imported above

<template>
  <div>
    <h1>Hello Vue composable-app 1</h1>
  </div>
</template>

Create a file called selfHosted.ts|js in the src directory where your composable app is, for example:

my-monorepo/
├- apps/
│  ├─ vue-host/
├─ composable-apps/
│  ├─ vue-app-1/
│  │  ├─ package.json
│  │  ├─ src/
│  │  │  ├─ VueApp1.vue
│  │  │  ├─ index.ts 👈
│  │  │  ├─ selfHosted.ts 👈
├─ package.json

Export a createRuntime function from the selfHosted.ts|js file. This is the runtime that will be used when the app runs in isolation, meaning without a host.

// my-monorepo/composable-apps/vue-app-1/src/selfHosted.ts
export { createRuntime } from "@my-org/runtime-vue";

:::info

Read @leanjs/core if you have not already created your own createRuntime function

:::

Components

HostProvider

You have to call createRuntimeBindings to create a HostProvider component before you use it. HostProvider stores in a Vue context values that are shared across apps hosted in the same component tree. Props:

runtime prop - required

Your Lean runtime.

origin prop - optional

Origin where your remote composable apps are. During development, use the address where you run your Lean proxy dev server. Use the address of your CDN in production, e.g. https://cdn.example.com.

Example

<template>
    <HostProvider :runtime="runtime" :origin="origin">
      <NuxtPage />
    </HostProvider>
</template>

<script setup lang="ts">
  import { createRuntime, HostProvider } from "./shared-runtime";

  const runtime = createRuntime({
    context: { appName: "AppExample" },
  });

  const origin = process.env.MICROFRONTENDS_ORIGIN;
</script>

Host

It hosts a composable app in a Vue host.

You can read more about this in @leanjs/nuxt