Skip to content

Commit

Permalink
chore: deprecated @webview-bridge/vue (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
gronxb authored Oct 24, 2024
1 parent 4a696db commit 3de461c
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 150 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
[![NPM](https://img.shields.io/npm/v/%40webview-bridge%2Freact-native/latest?label=%40webview-bridge%2Freact-native)](https://www.npmjs.com/package/@webview-bridge/react-native)
[![NPM](https://img.shields.io/npm/v/%40webview-bridge%2Fweb/latest?label=%40webview-bridge%2Fweb)](https://www.npmjs.com/package/@webview-bridge/web)
[![NPM](https://img.shields.io/npm/v/%40webview-bridge%2Freact/latest?label=%40webview-bridge%2Freact)](https://www.npmjs.com/package/@webview-bridge/react)
[![NPM](https://img.shields.io/npm/v/%40webview-bridge%2Fvue/latest?label=%40webview-bridge%2Fvue)](https://www.npmjs.com/package/@webview-bridge/vue)

**Fully Type-Safe Integration for React Native WebView and Web**

Expand Down
36 changes: 29 additions & 7 deletions docs/shared-state/vue.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ This guide integrates the state declared in [Shared State in React Native](./rea
::: code-group

```sh [npm]
$ npm add @webview-bridge/vue @webview-bridge/web
$ npm add @webview-bridge/web
```

```sh [pnpm]
$ pnpm add @webview-bridge/vue @webview-bridge/web
$ pnpm add @webview-bridge/web
```

```sh [yarn]
$ yarn add @webview-bridge/vue @webview-bridge/web
$ yarn add @webview-bridge/web
```

:::
Expand Down Expand Up @@ -51,19 +51,42 @@ export type AppBridge = typeof appBridge;
### Web Part
```tsx
// This file is src/bridge.ts
import type { Bridge, BridgeStore } from "@webview-bridge/web";
import { getCurrentInstance, onScopeDispose, ref } from "vue";

import { linkBridge } from "@webview-bridge/web";
import { ref } from "vue";
import type { AppBridge } from "";

export const isReady = ref(false);

export const bridge = linkBridge<AppBridge>({
throwOnError: true,
onReady: () => {
console.log("bridge is ready");
isReady.value = true;
console.log("bridge is ready");
},
});

export const bridgeStore = bridge.store;

export function useBridge<T extends Bridge>(
store: Omit<BridgeStore<T>, "setState">,
) {
const state = ref(store.getState());

const unsubscribe = store.subscribe((newState) => {
state.value = newState;
});

if (getCurrentInstance()) {
onScopeDispose(() => {
unsubscribe?.();
});
}

return state;
}

```

## useBridge
Expand All @@ -73,8 +96,7 @@ Insert the previously `bridge.store` as the first argument.

```vue
<script setup lang="ts">
import { bridge, isReady } from "./bridge";
import { useBridge } from "@webview-bridge/vue";
import { bridge, isReady, useBridge } from "./bridge";
const bridgeStore = useBridge(bridge.store);
</script>
Expand Down
1 change: 0 additions & 1 deletion example/shared-state-integration-vue/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"preview": "vite preview"
},
"dependencies": {
"@webview-bridge/vue": "workspace:^",
"@webview-bridge/web": "workspace:^",
"vue": "^3.5.12"
},
Expand Down
3 changes: 1 addition & 2 deletions example/shared-state-integration-vue/vue/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { bridge, isReady } from "./bridge";
import { useBridge } from "@webview-bridge/vue";
import { bridge, isReady, useBridge } from "./bridge";
const handleOpenInAppBrowser = () => {
if (bridge.isNativeMethodAvailable("openInAppBrowser") === true) {
Expand Down
22 changes: 21 additions & 1 deletion example/shared-state-integration-vue/vue/src/bridge.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Bridge, BridgeStore } from "@webview-bridge/web";
import { getCurrentInstance, onScopeDispose, ref } from "vue";

import { linkBridge } from "@webview-bridge/web";
import type { AppBridge } from "@webview-bridge-example-shared-state-integration-vue/react-native/types";
import { ref } from "vue";

export const isReady = ref(false);

Expand All @@ -13,3 +15,21 @@ export const bridge = linkBridge<AppBridge>({
});

export const bridgeStore = bridge.store;

export function useBridge<T extends Bridge>(
store: Omit<BridgeStore<T>, "setState">,
) {
const state = ref(store.getState());

const unsubscribe = store.subscribe((newState) => {
state.value = newState;
});

if (getCurrentInstance()) {
onScopeDispose(() => {
unsubscribe?.();
});
}

return state;
}
Empty file.
5 changes: 0 additions & 5 deletions packages/vue/README.md

This file was deleted.

34 changes: 0 additions & 34 deletions packages/vue/esbuild.config.js

This file was deleted.

42 changes: 0 additions & 42 deletions packages/vue/package.json

This file was deleted.

1 change: 0 additions & 1 deletion packages/vue/src/index.ts

This file was deleted.

20 changes: 0 additions & 20 deletions packages/vue/src/useBridge.ts

This file was deleted.

21 changes: 0 additions & 21 deletions packages/vue/tsconfig.json

This file was deleted.

15 changes: 0 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3de461c

Please sign in to comment.