Compare commits

...

73 Commits

Author SHA1 Message Date
a0189921a5 2.0.19 2024-10-02 17:49:56 +02:00
b409f1aa55 fix(dependencies): Update dependencies to latest versions 2024-10-02 17:49:56 +02:00
57553aa7c8 2.0.18 2024-10-02 15:59:41 +02:00
c302cbdae4 fix(core): Fix type errors and typos in Smartstate class 2024-10-02 15:59:41 +02:00
fd6e3ba8b1 update description 2024-05-29 14:16:33 +02:00
8c3a7aa637 update tsconfig 2024-04-14 18:24:08 +02:00
8c0125a8c0 update tsconfig 2024-04-01 21:41:21 +02:00
40f3ffbdfb update npmextra.json: githost 2024-04-01 19:59:48 +02:00
d4e01a73d3 update npmextra.json: githost 2024-03-30 21:48:48 +01:00
641e77892a 2.0.17 2023-10-07 12:23:03 +02:00
0c1211778b fix(core): update 2023-10-07 12:23:03 +02:00
024f7f4f8f 2.0.16 2023-10-04 07:59:13 +02:00
8f1cba5078 fix(core): update 2023-10-04 07:59:12 +02:00
188f8057bf 2.0.15 2023-10-03 19:19:54 +02:00
99cb86258e fix(core): update 2023-10-03 19:19:54 +02:00
83976fa3f4 2.0.14 2023-10-03 16:20:35 +02:00
fe81307ca6 fix(core): update 2023-10-03 16:20:34 +02:00
3a119b50a2 2.0.13 2023-10-03 13:19:39 +02:00
d3332ccb3f fix(core): update 2023-10-03 13:19:38 +02:00
776eba09e9 2.0.12 2023-10-03 12:47:38 +02:00
b41ff5d495 fix(core): update 2023-10-03 12:47:38 +02:00
5f5f9db884 2.0.11 2023-10-03 12:47:13 +02:00
876042b446 fix(core): update 2023-10-03 12:47:12 +02:00
df2924577b 2.0.10 2023-10-03 07:53:29 +02:00
4abaea84f8 fix(core): update 2023-10-03 07:53:28 +02:00
de454b4c8d 2.0.9 2023-09-11 18:39:53 +02:00
961685b5bd fix(core): update 2023-09-11 18:39:52 +02:00
c622396d50 2.0.8 2023-07-27 15:20:48 +02:00
d130c1c6fd fix(core): update 2023-07-27 15:20:47 +02:00
f8a967aeac 2.0.7 2023-07-27 15:20:25 +02:00
abee699af8 fix(core): update 2023-07-27 15:20:24 +02:00
a21131eaf6 2.0.6 2023-04-13 14:22:32 +02:00
c4b214a308 fix(core): update 2023-04-13 14:22:31 +02:00
6db03eee83 2.0.5 2023-04-12 20:34:34 +02:00
efc5b54d2e fix(core): update 2023-04-12 20:34:34 +02:00
9860e43398 2.0.4 2023-04-04 21:52:27 +02:00
234117c8dd fix(core): update 2023-04-04 21:52:27 +02:00
371c6553cd 2.0.3 2023-04-04 21:44:17 +02:00
b6b738916f fix(core): update 2023-04-04 21:44:16 +02:00
fad7e0bc6b 2.0.2 2023-04-04 20:59:46 +02:00
fc4fb911ef fix(core): update 2023-04-04 20:59:45 +02:00
7e0dad1c10 2.0.1 2023-03-15 17:04:29 +01:00
0fb50714b9 fix(core): update 2023-03-15 17:04:29 +01:00
7e1821f37d 2.0.0 2022-03-25 13:31:21 +01:00
592228fc51 BREAKING CHANGE(core): switch to esm 2022-03-25 13:31:21 +01:00
431089e23f 1.0.23 2022-01-24 06:42:45 +01:00
5b64733d91 fix(core): update 2022-01-24 06:42:43 +01:00
2da2a43a09 1.0.22 2022-01-24 06:39:37 +01:00
f7887a6663 fix(core): update 2022-01-24 06:39:36 +01:00
be505ee915 1.0.21 2020-11-29 23:51:06 +00:00
9584f403b1 fix(core): update 2020-11-29 23:51:05 +00:00
993a100eae 1.0.20 2020-11-29 23:33:56 +00:00
29f0307ef8 fix(core): update 2020-11-29 23:33:55 +00:00
9413c5bcdc 1.0.19 2020-11-29 23:31:32 +00:00
1d5fb320f4 fix(core): update 2020-11-29 23:31:31 +00:00
69e905ad76 1.0.18 2020-11-29 23:28:45 +00:00
7b9ed9ee78 fix(core): update 2020-11-29 23:28:44 +00:00
f884807f33 1.0.17 2020-07-27 18:17:53 +00:00
f167800113 fix(core): update 2020-07-27 18:17:52 +00:00
c549d06a6b 1.0.16 2020-05-27 20:47:16 +00:00
23061c86eb fix(core): update 2020-05-27 20:47:15 +00:00
4d0567a95d 1.0.15 2020-05-18 04:10:37 +00:00
8524c95440 fix(core): update 2020-05-18 04:10:36 +00:00
b1fc60fc2e 1.0.14 2019-09-25 17:09:36 +02:00
8d296cf08d fix(core): update 2019-09-25 17:09:35 +02:00
b8d0ec55ad 1.0.13 2019-09-25 15:28:39 +02:00
1cf78441e2 fix(core): update 2019-09-25 15:28:39 +02:00
0f34c5de55 1.0.12 2019-04-30 10:46:29 +02:00
1bd8f8371b fix(core): update 2019-04-30 10:46:28 +02:00
ef263a85b4 1.0.11 2019-04-30 10:17:29 +02:00
315156aac5 fix(core): update 2019-04-30 10:17:29 +02:00
f90a61b38b 1.0.10 2019-03-22 12:03:58 +01:00
71af6f08f3 fix(core): update 2019-03-22 12:03:58 +01:00
25 changed files with 7691 additions and 2005 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

26
.gitignore vendored
View File

@ -1,6 +1,20 @@
.nogit/ .nogit/
node_modules/
coverage/ # artifacts
public/ coverage/
pages/ public/
.yarn/ pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
# custom

View File

@ -1,150 +0,0 @@
# gitzone standard
image: hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: "$CI_BUILD_STAGE"
stages:
- security
- test
- release
- metadata
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
tags:
- docker
- notpriv
snyk:
stage: security
script:
- npmci npm prepare
- npmci command npm install -g snyk
- npmci command npm install --ignore-scripts
- npmci command snyk test
tags:
- docker
- notpriv
sast:
stage: security
image: registry.gitlab.com/hosttoday/ht-docker-dbase:npmci
variables:
DOCKER_DRIVER: overlay2
allow_failure: true
services:
- docker:stable-dind
script:
- npmci npm prepare
- npmci npm install
- npmci command npm run build
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SAST_CONFIDENCE_LEVEL="${SAST_CONFIDENCE_LEVEL:-3}"
--volume "$PWD:/code"
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/sast:$SP_VERSION" /app/bin/run /code
artifacts:
reports:
sast: gl-sast-report.json
tags:
- docker
- priv
# ====================
# test stage
# ====================
testLTS:
stage: test
script:
- npmci npm prepare
- npmci node install lts
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
testSTABLE:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
- notpriv
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
image: docker:stable
allow_failure: true
services:
- docker:stable-dind
script:
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
- docker run
--env SOURCE_CODE="$PWD"
--volume "$PWD":/code
--volume /var/run/docker.sock:/var/run/docker.sock
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
artifacts:
paths: [codeclimate.json]
tags:
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- docker
- notpriv
pages:
image: hosttoday/ht-docker-node:npmci
stage: metadata
script:
- npmci command npm install -g typedoc typescript
- npmci npm prepare
- npmci npm install
- npmci command typedoc --module "commonjs" --target "ES2016" --out public/ ts/
tags:
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

11
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}

26
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}

149
changelog.md Normal file
View File

@ -0,0 +1,149 @@
# Changelog
## 2024-10-02 - 2.0.19 - fix(dependencies)
Update dependencies to latest versions
- Updated @git.zone/tsbuild to version ^2.1.84
- Updated @git.zone/tsbundle to version ^2.0.15
- Updated @git.zone/tsrun to version ^1.2.49
- Updated @git.zone/tstest to version ^1.0.90
- Updated @push.rocks/tapbundle to version ^5.3.0
- Updated @types/node to version ^22.7.4
- Updated @push.rocks/lik to version ^6.0.15
- Updated @push.rocks/smartjson to version ^5.0.20
- Updated @push.rocks/smartpromise to version ^4.0.4
- Updated @push.rocks/smartrx to version ^3.0.7
- Updated @push.rocks/webstore to version ^2.0.20
## 2024-10-02 - 2.0.18 - fix(core)
Fix type errors and typos in Smartstate class
- Updated type annotation in Smartstate class to ensure StatePartNameType extends string.
- Fixed a typo in the JSDoc comment: 'existing' instead of 'exiting'.
- Corrected improper type casting in the Smartstate class.
## 2024-05-29 - 2.0.17 - Maintenance
General updates and improvements.
- Updated project description
- Multiple updates to `tsconfig`
- Updated `npmextra.json` to include `githost`
## 2023-10-07 - 2.0.16 - Maintenance
General updates and improvements.
- Core update
## 2023-10-04 - 2.0.15 - Maintenance
General updates and improvements.
- Core update
## 2023-10-03 - 2.0.14 to 2.0.10 - Maintenance
General updates and improvements.
- Core updates
## 2023-09-11 - 2.0.9 - Maintenance
General updates and improvements.
- Core update
## 2023-09-11 - 2.0.8 - Maintenance
General updates and improvements.
- Core update
## 2023-07-27 - 2.0.7 - Maintenance
General updates and improvements.
- Core update
## 2023-07-27 - 2.0.6 - Maintenance
General updates and improvements.
- Core update
## 2023-04-13 - 2.0.5 - Maintenance
General updates and improvements.
- Core update
## 2023-04-12 - 2.0.4 - Maintenance
General updates and improvements.
- Core update
## 2023-04-04 - 2.0.3 to 2.0.1 - Maintenance
General updates and improvements.
- Core updates
## 2023-03-15 - 2.0.0 - Major Update
Core update with significant changes.
## 2022-03-25 - 1.0.23 - Major Update
Breaking changes and major updates.
- SWITCH TO ESM
## 2022-01-24 - 1.0.22 - Maintenance
General updates and improvements.
- Core updates
## 2020-11-30 - 1.0.21 to 1.0.20 - Maintenance
General updates and improvements.
- Core updates
## 2020-11-30 - 1.0.19 to 1.0.18 - Maintenance
General updates and improvements.
- Core updates
## 2020-07-27 - 1.0.17 to 1.0.16 - Maintenance
General updates and improvements.
- Core updates
## 2020-05-27 - 1.0.15 - Maintenance
General updates and improvements.
- Core update
## 2020-05-27 - 1.0.14 - Maintenance
General updates and improvements.
- Core update
## 2019-09-25 - 1.0.13 - Maintenance
General updates and improvements.
- Core update
## 2019-09-25 - 1.0.12 - Maintenance
General updates and improvements.
- Core updates
## 2019-04-30 - 1.0.11 to 1.0.10 - Maintenance
General updates and improvements.
- Core updates
## 2019-03-22 - 1.0.9 - Maintenance
General updates and improvements.
- Core update
## 2019-02-27 - 1.0.8 - Minor Update
Minor updates and improvements.
- Updated action generation
- Core update
## 2019-02-21 - 1.0.7 - Initial Release
Initial release of the project.
- Initial core implementation

View File

@ -1,4 +1,4 @@
Copyright (c) 2019 Lossless GmbH (hello@lossless.com) Copyright (c) 2019 Task Venture Capital GmbH (hello@task.vc)
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@ -4,13 +4,29 @@
"npmAccessLevel": "public" "npmAccessLevel": "public"
}, },
"gitzone": { "gitzone": {
"projectType": "npm",
"module": { "module": {
"githost": "gitlab.com", "githost": "code.foss.global",
"gitscope": "pushrocks", "gitscope": "push.rocks",
"gitrepo": "smartstate", "gitrepo": "smartstate",
"shortDescription": "a package that handles state in a good way", "description": "A package for handling and managing state in applications.",
"npmPackagename": "@pushrocks/smartstate", "npmPackagename": "@push.rocks/smartstate",
"license": "MIT" "license": "MIT",
"keywords": [
"state management",
"reactive programming",
"TypeScript",
"observables",
"web storage",
"state action",
"state selection",
"state notification",
"asynchronous state",
"cumulative notification"
]
} }
},
"tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
} }
} }

1575
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,64 @@
{ {
"name": "@pushrocks/smartstate", "name": "@push.rocks/smartstate",
"version": "1.0.9", "version": "2.0.19",
"private": false, "private": false,
"description": "a package that handles state in a good way", "description": "A package for handling and managing state in applications.",
"main": "dist/index.js", "main": "dist_ts/index.js",
"typings": "dist/index.d.ts", "typings": "dist_ts/index.d.ts",
"type": "module",
"author": "Lossless GmbH", "author": "Lossless GmbH",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild)", "build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
"format": "(gitzone format)" "buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.8", "@git.zone/tsbuild": "^2.1.84",
"@gitzone/tstest": "^1.0.15", "@git.zone/tsbundle": "^2.0.15",
"@pushrocks/tapbundle": "^3.0.7", "@git.zone/tsrun": "^1.2.49",
"@types/node": "^11.9.4", "@git.zone/tstest": "^1.0.90",
"tslint": "^5.12.1", "@push.rocks/tapbundle": "^5.3.0",
"tslint-config-prettier": "^1.18.0" "@types/node": "^22.7.4"
}, },
"dependencies": { "dependencies": {
"@pushrocks/lik": "^3.0.4", "@push.rocks/isohash": "^2.0.1",
"rxjs": "^6.4.0" "@push.rocks/lik": "^6.0.15",
"@push.rocks/smartjson": "^5.0.20",
"@push.rocks/smartpromise": "^4.0.4",
"@push.rocks/smartrx": "^3.0.7",
"@push.rocks/webstore": "^2.0.20"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
"readme.md"
],
"browserslist": [
"last 1 chrome versions"
],
"keywords": [
"state management",
"reactive programming",
"TypeScript",
"observables",
"web storage",
"state action",
"state selection",
"state notification",
"asynchronous state",
"cumulative notification"
],
"homepage": "https://code.foss.global/push.rocks/smartstate",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartstate.git"
} }
} }

6751
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

1
readme.hints.md Normal file
View File

@ -0,0 +1 @@

147
readme.md
View File

@ -1,26 +1,137 @@
# @pushrocks/smartstate # @push.rocks/smartstate
a package that handles state in a good way a package that handles state in a good way
## Availabililty and Links ## Install
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartstate)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartstate)
* [github.com (source mirror)](https://github.com/pushrocks/smartstate)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartstate/)
## Status for master To install `@push.rocks/smartstate`, you can use npm (Node Package Manager). Run the following command in your terminal:
[![build status](https://gitlab.com/pushrocks/smartstate/badges/master/build.svg)](https://gitlab.com/pushrocks/smartstate/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartstate/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartstate/commits/master) ```bash
[![npm downloads per month](https://img.shields.io/npm/dm/@pushrocks/smartstate.svg)](https://www.npmjs.com/package/@pushrocks/smartstate) npm install @push.rocks/smartstate --save
[![Known Vulnerabilities](https://snyk.io/test/npm/@pushrocks/smartstate/badge.svg)](https://snyk.io/test/npm/@pushrocks/smartstate) ```
[![TypeScript](https://img.shields.io/badge/TypeScript->=%203.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) This will add `@push.rocks/smartstate` to your project's dependencies.
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-prettier-ff69b4.svg)](https://prettier.io/)
## Usage ## Usage
For further information read the linked docs at the top of this readme. The `@push.rocks/smartstate` library provides an elegant way to handle state within your JavaScript or TypeScript projects, leveraging the power of Reactive Extensions (RxJS) and a structured state management strategy. In the following sections, we will explore the comprehensive capabilities of this package and how to effectively use them in various scenarios, ensuring a robust state management pattern in your applications.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) ### Getting Started
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
[![repo-footer](https://pushrocks.gitlab.io/assets/repo-footer.svg)](https://maintainedby.lossless.com) First, let's import the necessary components from the library:
```typescript
import { Smartstate, StatePart, StateAction } from '@push.rocks/smartstate';
```
### Creating a SmartState Instance
`Smartstate` acts as the container for your state parts. You can consider it as the root of your state management structure.
```typescript
const myAppSmartState = new Smartstate<YourStatePartNamesEnum>();
```
### Defining State Parts
State parts represent separable sections of your state, making it easier to manage and modularize. For example, you may have a state part for user data and another for application settings.
Define an enum for state part names for better management:
```typescript
enum AppStateParts {
UserState,
SettingsState
}
```
Now, let's create a state part within our `myAppSmartState` instance:
```typescript
interface IUserState {
isLoggedIn: boolean;
username?: string;
}
const userStatePart = await myAppSmartState.getStatePart<IUserState>(
AppStateParts.UserState,
{ isLoggedIn: false } // Initial state
);
```
### Subscribing to State Changes
You can subscribe to changes in a state part to perform actions accordingly:
```typescript
userStatePart.select().subscribe((currentState) => {
console.log(`User Logged In: ${currentState.isLoggedIn}`);
});
```
If you need to select a specific part of your state, you can pass a selector function:
```typescript
userStatePart.select(state => state.username).subscribe((username) => {
if (username) {
console.log(`Current user: ${username}`);
}
});
```
### Modifying State with Actions
Create actions to modify the state in a controlled manner:
```typescript
interface ILoginPayload {
username: string;
}
const loginUserAction = userStatePart.createAction<ILoginPayload>(async (statePart, payload) => {
return { ...statePart.getState(), isLoggedIn: true, username: payload.username };
});
// Dispatch the action to update the state
loginUserAction.trigger({ username: 'johnDoe' });
```
### Persistent State
`Smartstate` supports the concept of persistent states, where you can maintain state across sessions. To utilize this, specify a persistent mode when getting a state part:
```typescript
const settingsStatePart = await myAppSmartState.getStatePart<AppStateParts, ISettingsState>(
AppStateParts.SettingsState,
{ theme: 'light' }, // Initial state
'persistent' // Mode
);
```
This mode ensures that the state is saved and can be reloaded even after the application restarts, providing a seamless user experience.
### Comprehensive Usage
Putting it all together, `@push.rocks/smartstate` offers a flexible and powerful pattern for managing application state. By modularizing state parts, subscribing to state changes, and controlling state modifications through actions, developers can maintain a clean and scalable architecture. Combining these strategies with persistent states unlocks the full potential for creating dynamic and user-friendly applications.
Remember to leverage TypeScript for its excellent support for types and interfaces, enhancing your development experience with type checking and IntelliSense, ensuring a more reliable and maintainable codebase.
For more complex scenarios, consider combining multiple state parts, creating hierarchical state structures, and integrating with other state management solutions as needed. With `@push.rocks/smartstate`, the possibilities are vast, empowering you to tailor the state management approach to fit the unique requirements of your project.
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@ -1,49 +1,58 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@push.rocks/tapbundle';
import * as smartstate from '../ts/index'; import * as smartstate from '../ts/index.js';
type TMyStateParts = 'testStatePart'; type TMyStateParts = 'testStatePart';
interface TStatePartPayload { interface TStatePartPayload {
currentFavorites: string[]; currentFavorites: string[];
deep: { deep: {
hi: number; hi: number;
}; };
} }
let testState: smartstate.Smartstate<TMyStateParts>; let testState: smartstate.Smartstate<TMyStateParts>;
let testStatePart: smartstate.StatePart<TMyStateParts, TStatePartPayload>; let testStatePart: smartstate.StatePart<TMyStateParts, TStatePartPayload>;
tap.test('should create a new SmartState', async () => { tap.test('should create a new SmartState', async () => {
testState = new smartstate.Smartstate<TMyStateParts>(); testState = new smartstate.Smartstate<TMyStateParts>();
expect(testState).to.be.instanceOf(smartstate.Smartstate); expect(testState).toBeInstanceOf(smartstate.Smartstate);
}); });
tap.test('should create a new StatePart', async () => { tap.test('should create a new StatePart', async () => {
testStatePart = testState.getStatePart<TStatePartPayload>('testStatePart', { testStatePart = await testState.getStatePart<TStatePartPayload>('testStatePart', {
currentFavorites: [], currentFavorites: [],
deep: { deep: {
hi: 2 hi: 2,
} },
}); });
expect(testStatePart).to.be.instanceOf(smartstate.StatePart); expect(testStatePart).toBeInstanceOf(smartstate.StatePart);
console.log(testStatePart); console.log(testStatePart);
}); });
tap.test('should select something', async () => { tap.test('should select something', async () => {
testStatePart testStatePart
.select(state => state.deep.hi) .select((state) => state.deep.hi)
.subscribe(substate => { .subscribe((substate) => {
expect(substate).to.equal(2); expect(substate).toEqual(2);
}); });
}); });
tap.test('should dispatch a state action', async () => { tap.test('should dispatch a state action', async (tools) => {
const addFavourite = testStatePart.createAction<string>(async (statePart, payload) => { const done = tools.defer();
const currentState = statePart.getState(); const addFavourite = testStatePart.createAction<string>(async (statePart, payload) => {
currentState.currentFavorites.push(payload); const currentState = statePart.getState();
return currentState; currentState.currentFavorites.push(payload);
}); return currentState;
await testStatePart.dispatchAction(addFavourite, 'my favourite things'); });
expect(testStatePart.getState().currentFavorites).to.include('my favourite things'); testStatePart
}); .waitUntilPresent((state) => {
return state.currentFavorites[0];
tap.start(); })
.then(() => {
done.resolve();
});
await testStatePart.dispatchAction(addFavourite, 'my favourite things');
expect(testStatePart.getState().currentFavorites).toContain('my favourite things');
await done.promise;
});
tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartstate',
version: '2.0.19',
description: 'A package for handling and managing state in applications.'
}

View File

@ -1,5 +1,3 @@
export * from './smartstate.classes.smartstate'; export * from './smartstate.classes.smartstate.js';
export * from './smartstate.classes.statepart'; export * from './smartstate.classes.statepart.js';
export * from './smartstate.classes.statecollection'; export * from './smartstate.classes.stateaction.js';
export * from './smartstate.classes.stateaction';
export * from './smartstate.classes.stateobservable';

View File

@ -1,47 +1,73 @@
import * as plugins from './smartstate.plugins'; import * as plugins from './smartstate.plugins.js';
import { StatePart } from './smartstate.classes.statepart'; import { StatePart } from './smartstate.classes.statepart.js';
/** export type TInitMode = 'soft' | 'mandatory' | 'force' | 'persistent';
* Smartstate takes care of providing state
*/ /**
export class Smartstate<StatePartNameType> { * Smartstate takes care of providing state
statePartMap: { [key: string]: StatePart<StatePartNameType, any> } = {}; */
export class Smartstate<StatePartNameType extends string> {
constructor() {} public statePartMap: { [key in StatePartNameType]?: StatePart<StatePartNameType, any> } = {};
getStatePart<PayloadType>( constructor() {}
statePartNameArg: StatePartNameType,
initialArg?: PayloadType /**
): StatePart<StatePartNameType, PayloadType> { * Allows getting and initializing a new statepart
if (this.statePartMap[statePartNameArg as any]) { * initMode === 'soft' it will allow existing stateparts
if (initialArg) { * initMode === 'mandatory' will fail if there is an existing statepart
throw new Error( * initMode === 'force' will overwrite any existing statepart
`${statePartNameArg} already exists, yet you try to set an initial state again` * @param statePartNameArg
); * @param initialArg
} * @param initMode
return this.statePartMap[statePartNameArg as any]; */
} else { public async getStatePart<PayloadType>(
if (!initialArg) { statePartNameArg: StatePartNameType,
throw new Error( initialArg?: PayloadType,
`${statePartNameArg} does not yet exist, yet you don't provide an initial state` initMode?: TInitMode
); ): Promise<StatePart<StatePartNameType, PayloadType>> {
} if (this.statePartMap[statePartNameArg]) {
return this.createStatePart<PayloadType>(statePartNameArg, initialArg); if (initialArg && (!initMode || initMode !== 'soft')) {
} throw new Error(
} `${statePartNameArg} already exists, yet you try to set an initial state again`
);
private createStatePart<PayloadType>( }
statePartName: StatePartNameType, return this.statePartMap[statePartNameArg] as StatePart<StatePartNameType, PayloadType>;
initialPayloadArg: PayloadType } else {
): StatePart<StatePartNameType, PayloadType> { if (!initialArg) {
const newState = new StatePart<StatePartNameType, PayloadType>(statePartName); throw new Error(
newState.setState(initialPayloadArg); `${statePartNameArg} does not yet exist, yet you don't provide an initial state`
this.statePartMap[statePartName as any] = newState; );
return newState; }
} return this.createStatePart<PayloadType>(statePartNameArg, initialArg, initMode);
}
/** }
* dispatches an action on the main level
*/ /**
dispatch() {} * Creates a statepart
} * @param statePartName
* @param initialPayloadArg
*/
private async createStatePart<PayloadType>(
statePartName: StatePartNameType,
initialPayloadArg: PayloadType,
initMode?: TInitMode
): Promise<StatePart<StatePartNameType, PayloadType>> {
const newState = new StatePart<StatePartNameType, PayloadType>(
statePartName,
initMode === 'persistent'
? {
dbName: 'smartstate',
storeName: statePartName,
}
: null
);
await newState.init();
const currentState = newState.getState();
await newState.setState({
...initialPayloadArg,
...currentState,
});
this.statePartMap[statePartName] = newState;
return newState;
}
}

View File

@ -1,13 +1,20 @@
import * as plugins from './smartstate.plugins'; import * as plugins from './smartstate.plugins.js';
import { StatePart } from './smartstate.classes.statepart'; import { StatePart } from './smartstate.classes.statepart.js';
export interface IActionDef<TStateType, TActionPayloadType> { export interface IActionDef<TStateType, TActionPayloadType> {
(stateArg: StatePart<any, TStateType>, actionPayload: TActionPayloadType): Promise<TStateType>; (stateArg: StatePart<any, TStateType>, actionPayload: TActionPayloadType): Promise<TStateType>;
} }
/** /**
* an actionmodifier for the state * an actionmodifier for the state
*/ */
export class StateAction<TStateType, TActionPayloadType> { export class StateAction<TStateType, TActionPayloadType> {
constructor(public actionDef: IActionDef<TStateType, TActionPayloadType>) {} constructor(
} public statePartRef: StatePart<any, any>,
public actionDef: IActionDef<TStateType, TActionPayloadType>
) {}
public trigger(payload: TActionPayloadType) {
this.statePartRef.dispatchAction(this, payload);
}
}

View File

@ -1,12 +0,0 @@
import * as plugins from './smartstate.plugins';
import { StatePart } from './smartstate.classes.statepart';
/**
* A StatePartCollection is a collection of StateParts.
* It can be used for expressing interest in a certain set of StateParts.
*/
export class StatePartCollection<StatePartNameType, T> extends StatePart<StatePartNameType, T> {
constructor(nameArg: StatePartNameType) {
super(nameArg);
}
}

View File

@ -1,13 +0,0 @@
import * as plugins from './smartstate.plugins';
/**
* State observable observes a StatePart and notifies everyone interested
*/
export class StateObservable {
/**
* creates an observable from a StateCollection
*/
public static fromStatePartCollection(filterArg?: () => any) {}
constructor() {}
}

View File

@ -1,72 +1,157 @@
import * as plugins from './smartstate.plugins'; import * as plugins from './smartstate.plugins.js';
import { StateAction, type IActionDef } from './smartstate.classes.stateaction.js';
import { Observable, Subject } from 'rxjs';
import { startWith, takeUntil, map } from 'rxjs/operators'; export class StatePart<TStatePartName, TStatePayload> {
public name: TStatePartName;
import { StateAction, IActionDef } from './smartstate.classes.stateaction'; public state = new plugins.smartrx.rxjs.Subject<TStatePayload>();
public stateStore: TStatePayload;
export class StatePart<TStatePartName, TStatePayload> { private cumulativeDeferred = plugins.smartpromise.cumulativeDefer();
name: TStatePartName;
state = new Subject<TStatePayload>(); private webStoreOptions: plugins.webstore.IWebStoreOptions;
stateStore: TStatePayload; private webStore: plugins.webstore.WebStore<TStatePayload> | null = null; // Add WebStore instance
constructor(nameArg: TStatePartName) { constructor(nameArg: TStatePartName, webStoreOptionsArg?: plugins.webstore.IWebStoreOptions) {
this.name = nameArg; this.name = nameArg;
}
// Initialize WebStore if webStoreOptions are provided
/** if (webStoreOptionsArg) {
* gets the state from the state store this.webStoreOptions = webStoreOptionsArg;
*/ }
getState(): TStatePayload { }
return this.stateStore;
} /**
* initializes the webstore
/** */
* sets the stateStore to the new state public async init() {
* @param newStateArg if (this.webStoreOptions) {
*/ this.webStore = new plugins.webstore.WebStore<TStatePayload>(this.webStoreOptions);
setState(newStateArg: TStatePayload) { await this.webStore.init();
this.stateStore = newStateArg; const storedState = await this.webStore.get(String(this.name));
this.notifyChange(); if (storedState) {
} this.stateStore = storedState;
this.notifyChange();
/** }
* notifies of a change on the state }
*/ }
notifyChange() {
this.state.next(this.stateStore); /**
} * gets the state from the state store
*/
/** public getState(): TStatePayload {
* selects a state or a substate return this.stateStore;
*/ }
select<T = TStatePayload>(selectorFn?: (state: TStatePayload) => T): Observable<T> {
if (!selectorFn) { /**
selectorFn = (state: TStatePayload) => <T>(<any>state); * sets the stateStore to the new state
} * @param newStateArg
*/
const mapped = this.state.pipe( public async setState(newStateArg: TStatePayload) {
startWith(this.getState()), this.stateStore = newStateArg;
map(selectorFn) this.notifyChange();
);
// Save state to WebStore if initialized
return mapped; if (this.webStore) {
} await this.webStore.set(String(this.name), newStateArg);
}
/** return this.stateStore;
* creates an action capable of modifying the state }
*/
createAction<TActionPayload>( /**
actionDef: IActionDef<TStatePayload, TActionPayload> * notifies of a change on the state
): StateAction<TStatePayload, TActionPayload> { */
return new StateAction(actionDef); public notifyChange() {
} const createStateHash = (stateArg: any) => {
return plugins.isohash.sha256FromString(plugins.smartjson.stringify(stateArg));
/** };
* dispatches an action on the statepart level if (
*/ this.stateStore &&
async dispatchAction<T>(stateAction: StateAction<TStatePayload, T>, actionPayload: T) { this.lastStateNotificationPayloadHash &&
const newState = await stateAction.actionDef(this, actionPayload); createStateHash(this.stateStore) === this.lastStateNotificationPayloadHash
this.setState(newState); ) {
} return;
} } else {
this.lastStateNotificationPayloadHash = this.stateStore;
}
this.state.next(this.stateStore);
}
private lastStateNotificationPayloadHash: any;
/**
* creates a cumulative notification by adding a change notification at the end of the call stack;
*/
public notifyChangeCumulative() {
// TODO: check viability
setTimeout(() => this.state.next(this.stateStore), 0);
}
/**
* selects a state or a substate
*/
public select<T = TStatePayload>(
selectorFn?: (state: TStatePayload) => T
): plugins.smartrx.rxjs.Observable<T> {
if (!selectorFn) {
selectorFn = (state: TStatePayload) => <T>(<any>state);
}
const mapped = this.state.pipe(
plugins.smartrx.rxjs.ops.startWith(this.getState()),
plugins.smartrx.rxjs.ops.map((stateArg) => {
try {
return selectorFn(stateArg);
} catch (e) {
// Nothing here
}
})
);
return mapped;
}
/**
* creates an action capable of modifying the state
*/
public createAction<TActionPayload>(
actionDef: IActionDef<TStatePayload, TActionPayload>
): StateAction<TStatePayload, TActionPayload> {
return new StateAction(this, actionDef);
}
/**
* dispatches an action on the statepart level
*/
public async dispatchAction<T>(stateAction: StateAction<TStatePayload, T>, actionPayload: T): Promise<TStatePayload> {
await this.cumulativeDeferred.promise;
const newState = await stateAction.actionDef(this, actionPayload);
await this.setState(newState);
return this.getState();
}
/**
* waits until a certain part of the state becomes available
* @param selectorFn
*/
public async waitUntilPresent<T = TStatePayload>(
selectorFn?: (state: TStatePayload) => T
): Promise<T> {
const done = plugins.smartpromise.defer<T>();
const selectedObservable = this.select(selectorFn);
const subscription = selectedObservable.subscribe(async (value) => {
if (value) {
done.resolve(value);
}
});
const result = await done.promise;
subscription.unsubscribe();
return result;
}
/**
* is executed
*/
public async stateSetup(
funcArg: (statePartArg?: StatePart<any, TStatePayload>) => Promise<TStatePayload>
) {
const resultPromise = funcArg(this);
this.cumulativeDeferred.addPromise(resultPromise);
this.setState(await resultPromise);
}
}

View File

@ -1,7 +1,7 @@
import { Observable } from 'rxjs'; import * as isohash from '@push.rocks/isohash';
import * as smartjson from '@push.rocks/smartjson';
const rxjsPart = { import * as smartpromise from '@push.rocks/smartpromise';
Observable import * as smartrx from '@push.rocks/smartrx';
}; import * as webstore from '@push.rocks/webstore';
export { rxjsPart }; export { isohash, smartjson, smartpromise, smartrx, webstore };

14
tsconfig.json Normal file
View File

@ -0,0 +1,14 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}

View File

@ -1,17 +0,0 @@
{
"extends": ["tslint:latest", "tslint-config-prettier"],
"rules": {
"semicolon": [true, "always"],
"no-console": false,
"ordered-imports": false,
"object-literal-sort-keys": false,
"member-ordering": {
"options":{
"order": [
"static-method"
]
}
}
},
"defaultSeverity": "warning"
}