Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add svelte and vue front-end SDKs #1760

Merged
merged 9 commits into from
Jun 29, 2022
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@ To connect your application to Unleash you'll need to use a client SDK for your

The front-end SDKs connects via the [Unleash Proxy](https://docs.getunleash.io/sdks/unleash-proxy) in order to ensure privacy, scalability and security.

- [Android SDK](https://docs.getunleash.io/sdks/android_proxy_sdk)
- [Javascript SDK](https://docs.getunleash.io/sdks/proxy-javascript)
- [React SDK](https://docs.getunleash.io/sdks/proxy-react)
- [iOS SDK](https://docs.getunleash.io/sdks/proxy-ios)
- [Android Proxy SDK](https://docs.getunleash.io/sdks/android_proxy_sdk)
- [iOS Proxy SDK](https://docs.getunleash.io/sdks/proxy-ios)
- [JavaScript Proxy SDK](https://docs.getunleash.io/sdks/proxy-javascript)
- [React Proxy SDK](https://docs.getunleash.io/sdks/proxy-react)
- [Svelte Proxy SDK](https://docs.getunleash.io/sdks/proxy-svelte)
- [Vue Proxy SDK](https://docs.getunleash.io/sdks/proxy-vue)

**Community SDKs:**

Expand Down
143 changes: 75 additions & 68 deletions website/docs/sdks/index.md

Large diffs are not rendered by default.

39 changes: 19 additions & 20 deletions website/docs/sdks/proxy-react.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
---
id: proxy-react
title: React proxy SDK
title: React Proxy SDK
---

This library is meant to be used with the [unleash-proxy](https://github.com/Unleash/unleash-proxy). The proxy application layer will sit between your unleash instance and your client applications, and provides performance and security benefits. DO NOT TRY to connect this library directly to the unleash instance, as the datasets follow different formats because the proxy only returns evaluated toggle information.

For more detailed information, check out [the React Proxy SDK on GitHub](https://github.com/Unleash/proxy-client-react).

For more detailed information, check out the [React Proxy SDK on GitHub](https://github.com/Unleash/proxy-client-react).

## Installation

Expand All @@ -21,12 +20,14 @@ npm install @unleash/proxy-client-react unleash-proxy-client
The snippet below shows you how to initialize the client. We recommend that you do this in your entry point file (typically index.js/ts) to ensure that you only have _one_ instance of it.

The configuration variables are:

- **`url`**

Your proxy's URL.
Your proxy's URL.

- **`clientKey`**

One of your proxy's [designated client keys (also known as proxy secrets)](unleash-proxy#configuration-variables).
One of your proxy's [designated client keys (also known as proxy secrets)](unleash-proxy#configuration-variables).

- **`refreshInterval`**

Expand All @@ -40,7 +41,6 @@ The configuration variables are:

The environment that your application runs in. This corresponds to the environment field in [the Unleash Context](../user_guide/unleash-context.md). Note that this is separate from the newer [Environments feature](../user_guide/environments.md).


```jsx
import { FlagProvider } from '@unleash/proxy-client-react';

Expand All @@ -58,7 +58,7 @@ ReactDOM.render(
<App />
</FlagProvider>
</React.StrictMode>,
document.getElementById('root')
document.getElementById('root'),
);
```

Expand All @@ -73,9 +73,9 @@ const TestComponent = () => {
const enabled = useFlag('travel.landing');

if (enabled) {
return <SomeComponent />
return <SomeComponent />;
}
return <AnotherComponent />
return <AnotherComponent />;
};

export default TestComponent;
Expand All @@ -89,12 +89,12 @@ import { useVariant } from '@unleash/proxy-client-react';
const TestComponent = () => {
const variant = useVariant('travel.landing');

if (variant.enabled && variant.name === "SomeComponent") {
return <SomeComponent />
} else if (variant.enabled && variant.name === "AnotherComponent") {
return <AnotherComponent />
if (variant.enabled && variant.name === 'SomeComponent') {
return <SomeComponent />;
} else if (variant.enabled && variant.name === 'AnotherComponent') {
return <AnotherComponent />;
}
return <DefaultComponent />
return <DefaultComponent />;
};

export default TestComponent;
Expand All @@ -105,16 +105,15 @@ export default TestComponent;
Follow the following steps in order to update the unleash context:

```jsx
import { useUnleashContext, useFlag } from '@unleash/proxy-client-react'
import { useUnleashContext, useFlag } from '@unleash/proxy-client-react';

const MyComponent = ({ userId }) => {
const variant = useFlag("my-toggle");
const variant = useFlag('my-toggle');
const updateContext = useUnleashContext();

useEffect(() => {
// context is updated with userId
updateContext({ userId })
}, [])
}

updateContext({ userId });
}, []);
};
```
35 changes: 19 additions & 16 deletions website/docs/sdks/proxy-svelte.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
id: proxy-svelte
title: Svelte proxy SDK
title: Svelte Proxy SDK
---

<div class="alert alert--info" role="alert">
<em>Svelte proxy SDK is currently at version 0.0.2 and is experimental</em>.
<em>Svelte Proxy SDK is currently at version 0.0.2 and is experimental</em>.
</div>
<br/>

This library is meant to be used with the [unleash-proxy](https://github.com/Unleash/unleash-proxy). The proxy application layer will sit between your unleash instance and your client applications, and provides performance and security benefits. DO NOT TRY to connect this library directly to the unleash instance, as the datasets follow different formats because the proxy only returns evaluated toggle information.

For more detailed information, check out [the svelte Proxy SDK on GitHub](https://github.com/Unleash/proxy-client-svelte).
For more detailed information, check out the [Svelte Proxy SDK on GitHub](https://github.com/Unleash/proxy-client-svelte).

## Installation

Expand All @@ -22,7 +22,7 @@ npm install @unleash/proxy-client-svelte

Import the provider like this in your entrypoint file (typically index.svelte):

```html
```jsx
<script lang="ts">
let FlagProvider;

Expand All @@ -47,7 +47,7 @@ Import the provider like this in your entrypoint file (typically index.svelte):

Alternatively, you can pass your own client in to the FlagProvider:

```html
```jsx
<script lang="ts">
import { UnleashClient } from '@unleash/proxy-client-svelte';

Expand Down Expand Up @@ -81,17 +81,21 @@ By default, the Unleash client will start polling the Proxy for toggles immediat
- setting the `startClient` prop to `false`
- passing a client instance to the `FlagProvider`

```html
<svelte:component this={FlagProvider} unleashClient={client} startClient={false}>
<App />
```jsx
<svelte:component
this={FlagProvider}
unleashClient={client}
startClient={false}
>
<App />
</svelte:component>
```

Deferring the client start gives you more fine-grained control over when to start fetching the feature toggle configuration. This could be handy in cases where you need to get some other context data from the server before fetching toggles, for instance.

To start the client, use the client's `start` method. The below snippet of pseudocode will defer polling until the end of the `asyncProcess` function.

```html
```jsx
<script lang="ts">
const client = new UnleashClient({
/* ... */
Expand All @@ -111,13 +115,13 @@ To start the client, use the client's `start` method. The below snippet of pseud
</svelte:component>
```

## Usage
# Usage
nunogois marked this conversation as resolved.
Show resolved Hide resolved

## Check feature toggle status

To check if a feature is enabled:

```html
```jsx
<script lang="ts">
import { useFlag } from '@unleash/proxy-client-svelte';

Expand All @@ -135,7 +139,7 @@ To check if a feature is enabled:

To check variants:

```html
```jsx
<script lang="ts">
import { useVariant } from '@unleash/proxy-client-svelte';

Expand All @@ -153,10 +157,9 @@ To check variants:

## Defer rendering until flags fetched

useFlagsStatus retrieves the ready state and error events.
Follow the following steps in order to delay rendering until the flags have been fetched.
useFlagsStatus retrieves the ready state and error events. Follow the following steps in order to delay rendering until the flags have been fetched.

```html
```jsx
<script lang="ts">
import { useFlagsStatus } from '@unleash/proxy-client-svelte';
const { flagsReady, flagsError } = useFlagsStatus();
Expand All @@ -173,7 +176,7 @@ Follow the following steps in order to delay rendering until the flags have been

Follow the following steps in order to update the unleash context:

```html
```jsx
<script lang="ts">
import { useUnleashContext, useFlag } from '@unleash/proxy-client-svelte';

Expand Down
9 changes: 4 additions & 5 deletions website/docs/sdks/proxy-vue.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
id: proxy-vue
title: Vue proxy SDK
title: Vue Proxy SDK
---

<div class="alert alert--info" role="alert">
<em>Vue proxy SDK is currently at version 0.0.1 and is experimental</em>.
<em>Vue Proxy SDK is currently at version 0.0.1 and is experimental</em>.
</div>
<br/>

This library is meant to be used with the [unleash-proxy](https://github.com/Unleash/unleash-proxy). The proxy application layer will sit between your unleash instance and your client applications, and provides performance and security benefits. DO NOT TRY to connect this library directly to the unleash instance, as the datasets follow different formats because the proxy only returns evaluated toggle information.

For more detailed information, check out [the vue Proxy SDK on GitHub](https://github.com/Unleash/proxy-client-vue).
For more detailed information, check out the [Vue Proxy SDK on GitHub](https://github.com/Unleash/proxy-client-vue).

## Installation

Expand Down Expand Up @@ -140,8 +140,7 @@ const variant = useVariant('travel.landing')

## Defer rendering until flags fetched

useFlagsStatus retrieves the ready state and error events.
Follow the following steps in order to delay rendering until the flags have been fetched.
useFlagsStatus retrieves the ready state and error events. Follow the following steps in order to delay rendering until the flags have been fetched.

```jsx
import { useFlagsStatus } from '@unleash/proxy-client-vue'
Expand Down
10 changes: 6 additions & 4 deletions website/docs/sdks/unleash-proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ The Unleash Proxy takes the heavy lifting of evaluating toggles and only returns

However in some settings you would like a bit more logic around it to make it as fast as possible, and keep up to date with changes.

- [JavaScript Proxy SDK](/sdks/proxy-javascript)
- [React Proxy SDK](/sdks/proxy-react)
- [Android Proxy SDK](/sdks/android_proxy_sdk)
- [iOS Proxy SDK](/sdks/proxy-ios)
- [Android Proxy SDK](sdks/android-proxy.md)
- [iOS Proxy SDK](sdks/proxy-ios.md)
- [Javascript Proxy SDK](sdks/proxy-javascript.md)
- [React Proxy SDK](sdks/proxy-react.md)
- [Svelte Proxy SDK](sdks/proxy-svelte.md)
- [Vue Proxy SDK](sdks/proxy-vue.md)

The proxy is also ideal fit for serverless functions such as AWS Lambda. In that scenario the proxy can run on a small container near the serverless function, preferably in the same VPC, giving the lambda extremely fast access to feature flags, at a predictable cost.
10 changes: 6 additions & 4 deletions website/docs/user_guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ Secret key: proxy-123

Now you can open your application code and connect through one of the proxy SDKs:

- [Javascript Proxy SDK](sdks/proxy-javascript.md)
- [iOS Proxy SDK](sdks/proxy-ios.md)
- [Android Proxy SDK](sdks/android-proxy.md)
- [React](sdks/proxy-react.md)
- [iOS Proxy SDK](sdks/proxy-ios.md)
- [Javascript Proxy SDK](sdks/proxy-javascript.md)
- [React Proxy SDK](sdks/proxy-react.md)
- [Svelte Proxy SDK](sdks/proxy-svelte.md)
- [Vue Proxy SDK](sdks/proxy-vue.md)

Here is a connection example using the javascript proxy SDK:
Here is a connection example using the JavaScript Proxy SDK:

```javascript
import { UnleashClient } from 'unleash-proxy-client';
Expand Down