Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
euaaaio committed Oct 31, 2024
1 parent b730a63 commit ed1ca82
Show file tree
Hide file tree
Showing 11 changed files with 1,743 additions and 265 deletions.
38 changes: 38 additions & 0 deletions demo/components/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<div id="view">
<logo />
<with-stores v-if="isStoresMounted" />
<button @click="executeTest">
Execute Test
</button>
<button @click="toggleStores">
{{ isStoresMounted ? 'Unmount' : 'Mount' }} Stores
</button>
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import Logo from './Logo.vue'
import WithStores from './WithStores.vue';
import { run } from '../stores.js'
const isStoresMounted = ref(false)
function executeTest() {
run()
}
function toggleStores() {
isStoresMounted.value = !isStoresMounted.value
}
</script>

<style scoped>
#view {
display: grid;
gap: 1rem;
}
</style>
19 changes: 19 additions & 0 deletions demo/components/Logo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<template>
<svg id="logo" xmlns="http://www.w3.org/2000/svg" width="200" height="200">
<path id="p" d="M107.785 154 48.8 112.698 83.353 99.22l50.559 35.401L107.785 154ZM92.415 46l58.984 41.302-34.553 13.478-50.559-35.4L92.414 46Z"/>
</svg>
</template>

<style scoped>
#logo {
#p {
fill: #000;
}
@media (prefers-color-scheme: dark) {
#p {
fill: #fff;
}
}
}
</style>
11 changes: 11 additions & 0 deletions demo/components/WithStores.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template></template>

<script lang="ts" setup>
import { useStore } from '../../use-store';
import { $atom, $map, $deepMap } from '../stores.js'
const atom = useStore($atom)
const map = useStore($map)
const deepMap = useStore($deepMap)
</script>

28 changes: 28 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Nano Stores Demo</title>
<style>
html {
height: 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
min-height: 100%;
margin: 0;
background: #fff;
}
@media (prefers-color-scheme: dark) {
body {
background: #000;
}
}
</style>
</head>
<body>
<div id="app"></div>
<script type="module" src="./index.ts"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions demo/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createApp } from "vue";

import App from "./components/App.vue";

import { devtools } from "../devtools";
import { $atom, $deepMap, $map } from "./stores";

const app = createApp(App)

app.use(devtools, {
$atom,
$map,
$deepMap
})

app.mount('#app')
56 changes: 56 additions & 0 deletions demo/stores.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { delay } from 'nanodelay'
import { atom, deepMap, map, STORE_UNMOUNT_DELAY } from 'nanostores'

export let $atom = atom()
export let $map = map({
artworks: 213,
fullname: 'Nikolay Suetin',
id: 'A10',
username: 'suetin'
})
export let $deepMap = deepMap<{
artists: {
[key: string]: {
artworks: string[]
movement: null | string
}
}
}>({
artists: {
malevich: {
artworks: ['Black Square'],
movement: null
}
}
})

export async function run(): Promise<void> {
let unbindAtom = $atom.listen(() => {})
$atom.set(100)
$atom.set(101)
$atom.set(Number($atom.get()) + 1)
$atom.set(Number($atom.get()) + 1)
$atom.set(Number($atom.get()) + 1)
unbindAtom()
await delay(STORE_UNMOUNT_DELAY + 10)

$map.setKey('artworks', 303)

await delay(STORE_UNMOUNT_DELAY)
$map.setKey('username', 'chashnik')
$map.setKey('fullname', 'Ilya Chashnik')

await delay(STORE_UNMOUNT_DELAY)
$map.setKey('username', 'malevich')
$map.setKey('fullname', 'Kazimir Malevich')

$deepMap.setKey('artists.malevich.movement', 'Suprematism')

let artworks = ['White on White', 'Suprematist Composition', 'Black Circle']
for (let item of artworks) {
await delay(100)
let index = $deepMap.get().artists.malevich.artworks.length
$deepMap.setKey(`artists.malevich.artworks[${index}]`, item)
}
await delay(STORE_UNMOUNT_DELAY + 10)
}
10 changes: 10 additions & 0 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevTools from 'vite-plugin-vue-devtools'

export default defineConfig({
plugins: [
vue(),
vueDevTools()
]
})
2 changes: 1 addition & 1 deletion devtools/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface DevtoolsOptions extends CreatorLoggerOptions, LoggerOptions {
*/
export function devtools(
app: App,
stores: {
stores?: {
[key: string]: AnyStore | MapCreator
},
opts?: DevtoolsOptions
Expand Down
82 changes: 20 additions & 62 deletions devtools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,48 +101,6 @@ function createLogger(
store,
storeName,
{
action: {
end: ({ actionId, actionName }) => {
api.addTimelineEvent({
event: {
groupId: actionId,
subtitle: 'action was ended',
time: api.now(),
title: actionName
},
layerId: LAYER_ID
})
},

error: ({ actionId, actionName, error }) => {
api.addTimelineEvent({
event: {
data: {
message: error.message
},
groupId: actionId,
logType: 'error',
subtitle: 'action handled error',
time: api.now(),
title: actionName
},
layerId: LAYER_ID
})
},

start: ({ actionId, actionName }) => {
api.addTimelineEvent({
event: {
groupId: actionId,
subtitle: 'action was started',
time: api.now(),
title: actionName
},
layerId: LAYER_ID
})
}
},

change: ({ actionId, changed, newValue, oldValue, valueMessage }) => {
let data = {
changed,
Expand Down Expand Up @@ -372,6 +330,26 @@ export function devtools(app, storesOrCreators, opts = {}) {
setupDevtoolsPlugin({ ...PLUGIN_CONFIG, app }, _api => {
api = _api

if (storesOrCreators) {
for (let [storeName, store] of Object.entries(storesOrCreators)) {
let inspectorNode = {
children: [],
id: getNodeId(),
label: storeName,
tags: []
}

inspectorTree.push(inspectorNode)
api.sendInspectorTree(INSPECTOR_ID)

if (isCreator(store)) {
createCreatorLogger(api, app, store, storeName, inspectorNode, opts)
} else {
createLogger(api, app, store, storeName, inspectorNode, opts)
}
}
}

api.addTimelineLayer({
color: 0x0059d1,
id: LAYER_ID,
Expand Down Expand Up @@ -487,24 +465,4 @@ export function devtools(app, storesOrCreators, opts = {}) {
}
})
})

if (storesOrCreators) {
for (let [storeName, store] of Object.entries(storesOrCreators)) {
let inspectorNode = {
children: [],
id: getNodeId(),
label: storeName,
tags: []
}

inspectorTree.push(inspectorNode)
api.sendInspectorTree(INSPECTOR_ID)

if (isCreator(store)) {
createCreatorLogger(api, app, store, storeName, inspectorNode, opts)
} else {
createLogger(api, app, store, storeName, inspectorNode, opts)
}
}
}
}
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"vue"
],
"scripts": {
"demo": "vite ./demo",
"test:lint": "eslint .",
"test:coverage": "vitest run --coverage",
"test:types": "check-dts",
Expand All @@ -30,9 +31,9 @@
"node": "^18.0.0 || >=20.0.0"
},
"peerDependencies": {
"@nanostores/logger": ">=0.2.3",
"@vue/devtools-api": ">=6.5.0",
"nanostores": ">=0.9.2",
"@nanostores/logger": ">=0.4.0",
"@vue/devtools-api": ">=7.6.2",
"nanostores": ">=0.11.3",
"vue": ">=3.3.1"
},
"peerDependenciesMeta": {
Expand All @@ -45,15 +46,15 @@
},
"devDependencies": {
"@logux/eslint-config": "51.0.0",
"@nanostores/logger": "^0.2.3",
"@nanostores/logger": "^0.4.0",
"@size-limit/preset-small-lib": "^8.2.6",
"@testing-library/vue": "^7.0.0",
"@typescript-eslint/eslint-plugin": "^5.61.0",
"@typescript-eslint/parser": "^5.61.0",
"@vitejs/plugin-vue": "^4.2.3",
"@vitejs/plugin-vue": "^5.1.4",
"@vitest/coverage-v8": "^0.33.0",
"@vue/compiler-sfc": "^3.3.4",
"@vue/devtools-api": "^6.5.0",
"@vue/compiler-sfc": "^3.5.12",
"@vue/devtools-api": "^7.6.2",
"check-dts": "^0.7.2",
"clean-publish": "^4.2.0",
"eslint": "^8.44.0",
Expand All @@ -65,14 +66,15 @@
"happy-dom": "^10.0.3",
"nano-staged": "^0.8.0",
"nanodelay": "^2.0.2",
"nanostores": "^0.9.3",
"nanostores": "^0.11.3",
"prettier": "^3.0.0",
"simple-git-hooks": "^2.8.1",
"size-limit": "^8.2.6",
"typescript": "^5.1.6",
"vite": "^4.4.2",
"typescript": "^5.6.3",
"vite": "^5.4.10",
"vite-plugin-vue-devtools": "^7.6.2",
"vitest": "^0.33.0",
"vue": "^3.3.4"
"vue": "^3.5.12"
},
"simple-git-hooks": {
"pre-commit": "./node_modules/.bin/nano-staged"
Expand Down
Loading

0 comments on commit ed1ca82

Please sign in to comment.