Skip to content

Commit

Permalink
feat(examples): added further examples
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Mar 1, 2022
1 parent 46efb38 commit 5251cfe
Show file tree
Hide file tree
Showing 20 changed files with 307 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ docs/public

test-results.xml
.vercel

.reports
4 changes: 1 addition & 3 deletions app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
defineConfig,
} from 'vite';

// https://vitejs.dev/config/
export default defineConfig({
server: {
port: 6565,
Expand All @@ -13,8 +12,7 @@ export default defineConfig({
stringify: true,
},
build: {
sourcemap: true,
cssCodeSplit: true,
sourcemap: 'hidden',
commonjsOptions: {
esmExternals: true,
},
Expand Down
6 changes: 3 additions & 3 deletions app/vue-shim.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
declare module '*.vue' {
import type {
DefineComponent
DefineComponent,
} from 'vue';

const component: DefineComponent<{}, {}, any>;
export default component

export default component;
}
24 changes: 0 additions & 24 deletions examples/nuxt/app.vue

This file was deleted.

1 change: 1 addition & 0 deletions examples/nuxt/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {

// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
srcDir: 'src/',
modules: [
'@nuxtjs/harlem',
],
Expand Down
13 changes: 7 additions & 6 deletions examples/nuxt/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "@harlem/example-nuxt",
"private": true,
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
"start": "node .output/server/index.mjs"
},
"devDependencies": {
"nuxt3": "latest"
},
"dependencies": {
"@harlem/extension-compose": "^2.2.3",
"@harlem/extension-reset": "^2.2.3",
"@harlem/extension-storage": "^2.2.3",
"@harlem/extension-compose": "^2.3.0",
"@harlem/extension-reset": "^2.3.0",
"@harlem/extension-storage": "^2.3.0",
"@nuxtjs/harlem": "^1.0.1"
},
"devDependencies": {
"nuxt3": "latest"
}
}
21 changes: 21 additions & 0 deletions examples/nuxt/src/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div>
<h1>Welcome {{ fullName }}</h1>
<input type="text" placeholder="First name" v-model="firstName">
<input type="text" placeholder="Last name" v-model="lastName">
<div>
<button @click="reset()">Reset</button>
</div>
</div>
</template>

<script lang="ts" setup>
import {
reset,
fullName,
computeState,
} from './store';
const firstName = computeState(state => state.firstName);
const lastName = computeState(state => state.lastName);
</script>
4 changes: 3 additions & 1 deletion examples/nuxt/store.ts → examples/nuxt/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ export const {
}),
resetExtension(), // order is important!
],
});
});

export const fullName = getter('fullname', ({ firstName, lastName }) => `${firstName} ${lastName}`);
29 changes: 29 additions & 0 deletions examples/vite-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Nuxt 3 Minimal Starter

We recommend to look at the [documentation](https://v3.nuxtjs.org).

## Setup

Make sure to install the dependencies

```bash
yarn install
```

## Development

Start the development server on http://localhost:3000

```bash
yarn dev
```

## Production

Build the application for production:

```bash
yarn build
```

Checkout the [deployment documentation](https://v3.nuxtjs.org/docs/deployment).
16 changes: 16 additions & 0 deletions examples/vite-ts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Harlem Example Vite + TS Application</title>
<link rel="icon" type="image/png" href="/favicon.png" sizes="32x32"/>
<script type="module" src="/src/index.ts" defer></script>
</head>

<body>
<div id="app"></div>
</body>

</html>
21 changes: 21 additions & 0 deletions examples/vite-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@harlem/example-vite-ts",
"private": true,
"scripts": {
"start": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@harlem/core": "^2.3.0",
"@harlem/extension-compose": "^2.3.0",
"@harlem/extension-reset": "^2.3.0",
"@harlem/extension-storage": "^2.3.0",
"@harlem/plugin-devtools": "^2.3.0",
"vue": "^3.2.31"
},
"devDependencies": {
"@vitejs/plugin-vue": "^2.2.4",
"vite": "^2.8.5"
}
}
Binary file added examples/vite-ts/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions examples/vite-ts/src/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div>
<h1>Welcome {{ fullName }}</h1>
<input type="text" placeholder="First name" v-model="firstName">
<input type="text" placeholder="Last name" v-model="lastName">
<div>
<button @click="reset()">Reset</button>
</div>
</div>
</template>

<script lang="ts" setup>
import {
reset,
fullName,
computeState,
} from './store';
const firstName = computeState(state => state.firstName);
const lastName = computeState(state => state.lastName);
</script>
20 changes: 20 additions & 0 deletions examples/vite-ts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import App from './app.vue';
import Harlem from '@harlem/core';

import harlemDevtoolsPlugin from '@harlem/plugin-devtools';

import {
createApp,
} from 'vue';

function main() {
return createApp(App)
.use(Harlem, {
plugins: [
harlemDevtoolsPlugin(),
],
})
.mount('#app');
}

main();
28 changes: 28 additions & 0 deletions examples/vite-ts/src/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import composeExtension from '@harlem/extension-compose';
import storageExtension from '@harlem/extension-storage';
import resetExtension from '@harlem/extension-reset';

import {
createStore,
} from '@harlem/core';

export const {
state,
getter,
reset,
computeState,
} = createStore('app', {
firstName: 'John',
lastName: 'Smith',
}, {
extensions: [
composeExtension(),
storageExtension({
prefix: 'vite-ts',
restore: true,
}),
resetExtension(), // order is important!
],
});

export const fullName = getter('fullname', ({ firstName, lastName }) => `${firstName} ${lastName}`);
15 changes: 15 additions & 0 deletions examples/vite-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"resolveJsonModule": true,
"types": [
"vite/client"
]
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.vue",
"vue-shim.d.ts"
]
}
22 changes: 22 additions & 0 deletions examples/vite-ts/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import vuePlugin from '@vitejs/plugin-vue';

import {
defineConfig,
} from 'vite';

export default defineConfig({
json: {
stringify: true,
},
build: {
commonjsOptions: {
esmExternals: true,
},
},
define: {
'__VUE_OPTIONS_API__': false,
},
plugins: [
vuePlugin(),
],
});
9 changes: 9 additions & 0 deletions examples/vite-ts/vue-shim.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module '*.vue' {
import type {
DefineComponent,
} from 'vue';

const component: DefineComponent<{}, {}, any>;

export default component;
}
3 changes: 2 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ import {

export default defineConfig({
test: {
environment: 'jsdom',
watch: false,
environment: 'jsdom',
outputFile: 'test-results.xml',
reporters: [
'verbose',
'junit',
],
coverage: {
enabled: true,
reportsDirectory: './.reports/coverage',
reporter: [
'text-summary',
],
Expand Down
Loading

0 comments on commit 5251cfe

Please sign in to comment.