Skip to content

Commit 25a22c1

Browse files
GregHolmesVeskeR
authored andcommitted
Update liveobjects examples to use npm workspace and franken-ui component styling
1 parent 9f40624 commit 25a22c1

29 files changed

+380
-3899
lines changed

examples/liveobjects-live-counter/javascript/.env.example

-1
This file was deleted.

examples/liveobjects-live-counter/javascript/README.md

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1-
# Working with LiveCounter from LiveObjects
1+
# Synchronizing numeric values with LiveCounter
22

3-
This folder contains the code for LiveCounter (Typescript) - a demo of how you can leverage [Ably LiveObjects](https://ably.com/docs/liveobjects) to create, subscribe to, and update a LiveCounter object synchronized across clients in realtime.
3+
Enable clients to update and synchronize numerical values in an application in realtime.
4+
5+
LiveCounter provides a simple way to manage shared numerical state in realtime applications. Each counter represents a numerical value that clients can increment or decrement.
6+
7+
LiveCounters are useful for tracking values that need to be updated dynamically, such as votes, reaction counts, live leaderboards, game stats, or other numeric data points.
8+
9+
LiveCounters are implemented using [Ably LiveObjects](https://ably.com/docs/liveobjects). LiveObjects, as a feature of [Ably Pub/Sub](https://ably.com/docs/products/channels), contains a set of purpose-built APIs that abstract away the complexities of managing shared state between clients in an application. It is built on top of Ably's core platform, and so it provides the same performance guarantees and scaling potential.
10+
11+
## Resources
12+
13+
Use the following methods to interact with a LiveCounter in your application:
14+
15+
* [`liveObjects.getRoot()`](https://ably.com/docs/liveobjects) - retrieves the root object that serves as the starting point for storing and organizing LiveObjects state.
16+
* [`liveObjects.createCounter()`](https://ably.com/docs/liveobjects) - creates a new LiveCounter instance.
17+
* [`liveCounter.value()`](https://ably.com/docs/liveobjects/livecounter) - returns the current value of a counter.
18+
* [`liveCounter.increment()`](https://ably.com/docs/liveobjects/livecounter) - sends the operation message to the Ably system to increase the counter value.
19+
* [`liveCounter.decrement()`](https://ably.com/docs/liveobjects/livecounter) - sends the operation message to the Ably system to decrease the counter value.
20+
* [`liveCounter.subscribe()`](https://ably.com/docs/liveobjects/livecounter) - subscribes to LiveCounter updates by registering a listener.
21+
22+
Find out more about [LiveCounters](https://ably.com/docs/liveobjects/livecounter).
423

524
## Getting started
625

@@ -13,7 +32,7 @@ git clone [email protected]:ably/docs.git
1332
2. Change directory:
1433

1534
```sh
16-
cd /examples/liveobjects-live-counter/javascript/
35+
cd /examples/
1736
```
1837

1938
3. Rename the environment file:
@@ -33,7 +52,11 @@ yarn install
3352
6. Run the server:
3453

3554
```sh
36-
yarn run dev
55+
yarn run liveobjects-live-counter-javascript
3756
```
3857

3958
7. Try it out by opening two tabs to [http://localhost:5173/](http://localhost:5173/) with your browser to see the result.
59+
60+
## Open in CodeSandbox
61+
62+
In CodeSandbox, rename the `.env.example` file to `.env.local` and update the value of your `VITE_PUBLIC_ABLY_KEY` variable to use your Ably API key.
Binary file not shown.

examples/liveobjects-live-counter/javascript/index.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@ <h2 class="text-xl font-bold mb-4">Vote for your favorite Color</h2>
1616
<div class="flex justify-between items-center p-2 border-b space-x-4">
1717
<span class="text-red-500 font-semibold flex-grow">Red</span>
1818
<span class="font-bold text-gray-700" id="count-red">0</span>
19-
<button class="bg-blue-500 hover:bg-blue-600 text-white py-1 px-3 rounded vote-button" data-color="red">
19+
<button class="uk-btn uk-btn-primary uk-border-rounded-right whitespace-nowrap vote-button" data-color="red">
2020
Vote
2121
</button>
2222
</div>
2323

2424
<div class="flex justify-between items-center p-2 border-b space-x-4">
2525
<span class="text-green-500 font-semibold flex-grow">Green</span>
2626
<span class="font-bold text-gray-700" id="count-green">0</span>
27-
<button class="bg-blue-500 hover:bg-blue-600 text-white py-1 px-3 rounded vote-button" data-color="green">
27+
<button class="uk-btn uk-btn-primary uk-border-rounded-right whitespace-nowrap vote-button" data-color="green">
2828
Vote
2929
</button>
3030
</div>
3131

3232
<div class="flex justify-between items-center p-2 space-x-4">
3333
<span class="text-blue-500 font-semibold flex-grow">Blue</span>
3434
<span class="font-bold text-gray-700" id="count-blue">0</span>
35-
<button class="bg-blue-500 hover:bg-blue-600 text-white py-1 px-3 rounded vote-button" data-color="blue">
35+
<button class="uk-btn uk-btn-primary uk-border-rounded-right whitespace-nowrap vote-button" data-color="blue">
3636
Vote
3737
</button>
3838
</div>
3939
</div>
4040

41-
<button class="bg-blue-500 hover:bg-blue-600 text-white py-1 px-3 rounded" id="reset">Reset</button>
41+
<button class="uk-btn uk-btn-secondary uk-border-rounded-right" id="reset">Reset</button>
4242
</div>
4343
</div>
4444
<script type="module" src="src/script.ts"></script>
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
{
2-
"name": "liveobjects-live-counter",
2+
"name": "liveobjects-live-counter-javascript",
33
"version": "1.0.0",
44
"main": "index.js",
55
"license": "MIT",
66
"scripts": {
77
"dev": "vite",
88
"build": "tsc && vite build",
99
"preview": "vite preview"
10-
},
11-
"devDependencies": {
12-
"autoprefixer": "^10.4.20",
13-
"dotenv": "^16.4.5",
14-
"postcss": "^8.4.47",
15-
"tailwindcss": "^3.4.13",
16-
"typescript": "^5.6.3"
17-
},
18-
"dependencies": {
19-
"ably": "file:./ably-2.5.0-liveobjects.tgz",
20-
"nanoid": "^5.0.7",
21-
"vite": "^5.4.2"
2210
}
2311
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import baseConfig from '../../postcss.config';
2+
3+
const config = {
4+
...baseConfig,
5+
};
6+
7+
export default config;
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,60 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
@layer base {
6+
:root {
7+
--background: 0 0% 100%;
8+
--foreground: 20 14.3% 4.1%;
9+
--card: 0 0% 100%;
10+
--card-foreground: 20 14.3% 4.1%;
11+
--popover: 0 0% 100%;
12+
--popover-foreground: 20 14.3% 4.1%;
13+
--primary: 20 91% 54%;
14+
--primary-foreground: 60 9.1% 97.8%;
15+
--secondary: 209 100% 43%;
16+
--secondary-foreground: 60 9.1% 97.8%;
17+
--muted: 60 4.8% 95.9%;
18+
--muted-foreground: 25 5.3% 44.7%;
19+
--accent: 60 4.8% 95.9%;
20+
--accent-foreground: 24 9.8% 10%;
21+
--destructive: 0 84.2% 60.2%;
22+
--destructive-foreground: 60 9.1% 97.8%;
23+
--border: 20 5.9% 90%;
24+
--input: 20 5.9% 90%;
25+
--ring: 24.6 95% 53.1%;
26+
--radius: 0.5rem;
27+
--chart-1: 12 76% 61%;
28+
--chart-2: 173 58% 39%;
29+
--chart-3: 197 37% 24%;
30+
--chart-4: 43 74% 66%;
31+
--chart-5: 27 87% 67%;
32+
}
33+
34+
.dark {
35+
--background: 20 14.3% 4.1%;
36+
--foreground: 60 9.1% 97.8%;
37+
--card: 20 14.3% 4.1%;
38+
--card-foreground: 60 9.1% 97.8%;
39+
--popover: 20 14.3% 4.1%;
40+
--popover-foreground: 60 9.1% 97.8%;
41+
--primary: 20 91% 54%;
42+
--primary-foreground: 60 9.1% 97.8%;
43+
--secondary: 209 100% 43%;
44+
--secondary-foreground: 60 9.1% 97.8%;
45+
--muted: 12 6.5% 15.1%;
46+
--muted-foreground: 24 5.4% 63.9%;
47+
--accent: 12 6.5% 15.1%;
48+
--accent-foreground: 60 9.1% 97.8%;
49+
--destructive: 0 72.2% 50.6%;
50+
--destructive-foreground: 60 9.1% 97.8%;
51+
--border: 12 6.5% 15.1%;
52+
--input: 12 6.5% 15.1%;
53+
--ring: 20.5 90.2% 48.2%;
54+
--chart-1: 220 70% 50%;
55+
--chart-2: 160 60% 45%;
56+
--chart-3: 30 80% 55%;
57+
--chart-4: 280 65% 60%;
58+
--chart-5: 340 75% 55%;
59+
}
60+
}

examples/liveobjects-live-counter/javascript/tailwind.config.js

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import baseConfig from '../../tailwind.config';
2+
import type { Config } from 'tailwindcss';
3+
4+
const config: Config = {
5+
...baseConfig,
6+
};
7+
8+
export default config;
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
{
2-
"compilerOptions": {
3-
"lib": [
4-
"dom",
5-
"es2015"
6-
],
7-
"outDir": "./lib/cjs/",
8-
"sourceMap": true,
9-
"declaration": true,
10-
"noImplicitAny": true,
11-
"module": "commonjs",
12-
"target": "es2017",
13-
"allowJs": true,
14-
"moduleResolution": "node",
15-
"esModuleInterop": true
16-
},
17-
"include": [
18-
"src/**/*.ts*"
19-
],
20-
"exclude": [
21-
"node_modules",
22-
"dist",
23-
"lib"
24-
]
2+
"extends": "../../tsconfig.json",
3+
"include": ["./src/**/*.ts", "./src/**/*.tsx"],
4+
"exclude": ["../../node_modules", "../../dist", "../../lib"]
255
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import baseConfig from '../../vite.config';
12
import { defineConfig } from 'vite';
3+
import dotenv from 'dotenv';
4+
import path from 'path';
5+
6+
dotenv.config({ path: path.resolve(__dirname, '../../.env.local') });
27

38
export default defineConfig({
4-
css: {
5-
postcss: {
6-
plugins: [require('tailwindcss'), require('autoprefixer')],
7-
},
8-
},
9+
...baseConfig,
910
});

0 commit comments

Comments
 (0)