Skip to content

Commit

Permalink
feat(stores): stores library for nanoviews (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen authored Sep 3, 2024
1 parent 9869823 commit ed05c7e
Show file tree
Hide file tree
Showing 64 changed files with 11,350 additions and 5,539 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"rules": {
},
"ignorePatterns": [
"packages/*/dist/**/*"
"packages/*/dist/**/*",
"packages/*/package/**/*"
]
}
24 changes: 5 additions & 19 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,25 @@ on:
branches:
- main
jobs:
list-workspaces:
runs-on: ubuntu-latest
name: list workspaces
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
- id: set-matrix
run: node -e "console.log('::set-output name=matrix::' + JSON.stringify(fs.readdirSync('packages')))"
size:
runs-on: ubuntu-latest
needs: list-workspaces
strategy:
matrix:
workspace:
- nanoviews
- stores
name: ${{ matrix.workspace }} / size-limit
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
version: 9
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
cache: 'pnpm'
- name: Check size
uses: andresz1/size-limit-action@master
Expand All @@ -61,11 +47,11 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
version: 9
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
cache: 'pnpm'
- name: Check package.json files
run: pnpm --package=@trigen/lint-package-json dlx lint-package-json --monorepo
4 changes: 2 additions & 2 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
version: 9
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
Expand Down
54 changes: 50 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,55 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
- id: set-matrix
run: node -e "console.log('::set-output name=matrix::' + JSON.stringify(fs.readdirSync('packages')))"
types:
runs-on: ubuntu-latest
needs: list-workspaces
strategy:
matrix:
workspace: ${{ fromJson(needs.list-workspaces.outputs.matrix) }}
name: ${{ matrix.workspace }} / types
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Check types
run: pnpm --filter ${{ matrix.workspace }} --if-present test:types
lint:
runs-on: ubuntu-latest
needs: list-workspaces
strategy:
matrix:
workspace: ${{ fromJson(needs.list-workspaces.outputs.matrix) }}
name: ${{ matrix.workspace }} / lint
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 18
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Lint files
run: pnpm --filter ${{ matrix.workspace }} --if-present lint
unit:
runs-on: ubuntu-latest
needs: list-workspaces
Expand All @@ -32,16 +78,16 @@ jobs:
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
version: 9
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 16
node-version: 18
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Run tests
run: pnpm --filter ${{ matrix.workspace }} --if-present test
run: pnpm --filter ${{ matrix.workspace }} --if-present test:unit
- name: Collect coverage
uses: codecov/codecov-action@v4
if: success()
Expand Down
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodejs 22.4.1
pnpm 9.9.0
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/nanoviews.svg
[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/nanoviews


A small Direct DOM library for creating user interfaces.

- **Small**. Between 2.71 and 4.77 kB (minified and brotlied). Zero dependencies[*](#reactivity).
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"lint": "pnpm -r --parallel --if-present lint",
"test:unit": "pnpm -r --parallel --if-present test:unit",
"test:size": "pnpm -r --parallel --if-present test:size",
"test": "run -p lint test:unit",
"test:types": "pnpm -r --parallel --if-present test:types",
"test": "run -p lint test:unit test:types",
"commit": "cz",
"updateGitHooks": "simple-git-hooks"
},
Expand Down
7 changes: 4 additions & 3 deletions packages/nanoviews/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nanoviews",
"type": "module",
"version": "0.0.0",
"version": "0.0.0-alpha.2",
"description": "A small Direct DOM library for creating user interfaces.",
"author": "dangreen",
"license": "MIT",
Expand Down Expand Up @@ -62,7 +62,8 @@
"test:unit": "vitest run --coverage",
"test:unit:watch": "vitest watch",
"test:size": "size-limit",
"test": "run -p lint test:unit",
"test:types": "tsc --noEmit",
"test": "run -p lint test:unit test:types",
"storybook": "storybook dev -p 6006 --no-open"
},
"peerDependencies": {
Expand All @@ -81,7 +82,7 @@
"@storybook/addon-essentials": "^7.6.17",
"@storybook/test": "^7.0.0",
"@testing-library/dom": "^10.0.0",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/jest-dom": "^6.5.0",
"@testing-library/user-event": "^14.5.2",
"@vitest/coverage-v8": "^2.0.0",
"csstype": "^3.1.3",
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions packages/stores/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": [
"@trigen/eslint-config/typescript",
"@trigen/eslint-config/typescript-requiring-type-checking",
"@trigen/eslint-config/jest"
],
"env": {
"browser": true,
"node": true
},
"parserOptions": {
"tsconfigRootDir": "./packages/stores",
"project": ["./tsconfig.json"]
},
"rules": {
"@typescript-eslint/no-invalid-void-type": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"no-implicit-coercion": "off",
"consistent-return": "off",
"symbol-description": "off"
}
}
26 changes: 26 additions & 0 deletions packages/stores/.size-limit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"name": "All publics",
"path": "dist/index.js",
"import": "*",
"limit": "2.36 kB"
},
{
"name": "All internals",
"path": "dist/internals.js",
"import": "*",
"limit": "1.5 kB"
},
{
"name": "Atom",
"path": "dist/index.js",
"import": "{ atom }",
"limit": "297 B"
},
{
"name": "Popular set",
"path": "dist/index.js",
"import": "{ atom, record, computed, listen, subscribe }",
"limit": "963 B"
}
]
82 changes: 82 additions & 0 deletions packages/stores/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# @nanoviews/stores

[![ESM-only package][package]][package-url]
[![NPM version][npm]][npm-url]
[![Dependencies status][deps]][deps-url]
[![Install size][size]][size-url]
[![Build status][build]][build-url]
[![Coverage status][coverage]][coverage-url]

[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
[package-url]: https://nodejs.org/api/esm.html

[npm]: https://img.shields.io/npm/v/%40nanoviews%2Fstores.svg
[npm-url]: https://npmjs.com/package/@nanoviews/stores

[deps]: https://img.shields.io/librariesio/release/npm/%40nanoviews%2Fstores
[deps-url]: https://libraries.io/npm/%40nanoviews%2Fstores/tree

[size]: https://packagephobia.com/badge?p=%40nanoviews%2Fstores
[size-url]: https://packagephobia.com/result?p=%40nanoviews%2Fstores

[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/nanoviews/tests.yml?branch=main
[build-url]: https://github.com/TrigenSoftware/nanoviews/actions

[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/nanoviews.svg
[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/nanoviews

A small state management library for Nanoviews inspired by [Nano Stores](https://github.com/nanostores/nanostores).

- **Small**. Between 297 B and 2.36 kB (minified and brotlied). Zero dependencies.
- **Fast**. With small atomic and computed stores, you do not need to call the selector function for all components on every store change.
- Designed for best **Tree-Shaking**: only the code you use is included in your bundle.
- **TypeScript**-first.

```ts
// store/users.ts
import { list, push, record } from '@nanoviews/stores'

export const $users = list([] as User[], record)

export function addUser(user: User) {
push($users, user)
}
```

```ts
// store/admins.ts
import { computed, list, record } from '@nanoviews/stores'
import { $users } from './users.js'

export const $admins = list(
computed($users, users => users.filter(i => i.isAdmin)),
record
)
```

```tsx
// components/admins.ts
import { $admins } from '../stores/admins.js'

export const Admins = component$(() => ul()(
for$($admins, admin => li()(admin.name))
))
```

<hr />
<a href="#install">Install</a>
<!-- span>&nbsp;&nbsp;•&nbsp;&nbsp;</span -->
<br />
<hr />

## Install

```bash
pnpm add -D @nanoviews/stores
# or
npm i -D @nanoviews/stores
# or
yarn add -D @nanoviews/stores
```

*...Work in progress...*
Loading

0 comments on commit ed05c7e

Please sign in to comment.