https://github.com/allnulled/lsw-store
Store tool for LSW
https://github.com/allnulled/lsw-store
Last synced: about 1 year ago
JSON representation
Store tool for LSW
- Host: GitHub
- URL: https://github.com/allnulled/lsw-store
- Owner: allnulled
- License: other
- Created: 2025-01-27T07:46:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-24T17:50:06.000Z (about 1 year ago)
- Last Synced: 2025-03-24T18:46:09.499Z (about 1 year ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.html
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
lsw-store
/* From extension vscode.github */
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
.vscode-dark img[src$=\#gh-light-mode-only],
.vscode-light img[src$=\#gh-dark-mode-only],
.vscode-high-contrast:not(.vscode-high-contrast-light) img[src$=\#gh-light-mode-only],
.vscode-high-contrast-light img[src$=\#gh-dark-mode-only] {
display: none;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe WPC', 'Segoe UI', system-ui, 'Ubuntu', 'Droid Sans', sans-serif;
font-size: 14px;
line-height: 1.6;
}
.task-list-item {
list-style-type: none;
}
.task-list-item-checkbox {
margin-left: -20px;
vertical-align: middle;
pointer-events: none;
}
:root {
--color-note: #0969da;
--color-tip: #1a7f37;
--color-warning: #9a6700;
--color-severe: #bc4c00;
--color-caution: #d1242f;
--color-important: #8250df;
}
@media (prefers-color-scheme: dark) {
:root {
--color-note: #2f81f7;
--color-tip: #3fb950;
--color-warning: #d29922;
--color-severe: #db6d28;
--color-caution: #f85149;
--color-important: #a371f7;
}
}
.markdown-alert {
padding: 0.5rem 1rem;
margin-bottom: 16px;
color: inherit;
border-left: .25em solid #888;
}
.markdown-alert>:first-child {
margin-top: 0
}
.markdown-alert>:last-child {
margin-bottom: 0
}
.markdown-alert .markdown-alert-title {
display: flex;
font-weight: 500;
align-items: center;
line-height: 1
}
.markdown-alert .markdown-alert-title .octicon {
margin-right: 0.5rem;
display: inline-block;
overflow: visible !important;
vertical-align: text-bottom;
fill: currentColor;
}
.markdown-alert.markdown-alert-note {
border-left-color: var(--color-note);
}
.markdown-alert.markdown-alert-note .markdown-alert-title {
color: var(--color-note);
}
.markdown-alert.markdown-alert-important {
border-left-color: var(--color-important);
}
.markdown-alert.markdown-alert-important .markdown-alert-title {
color: var(--color-important);
}
.markdown-alert.markdown-alert-warning {
border-left-color: var(--color-warning);
}
.markdown-alert.markdown-alert-warning .markdown-alert-title {
color: var(--color-warning);
}
.markdown-alert.markdown-alert-tip {
border-left-color: var(--color-tip);
}
.markdown-alert.markdown-alert-tip .markdown-alert-title {
color: var(--color-tip);
}
.markdown-alert.markdown-alert-caution {
border-left-color: var(--color-caution);
}
.markdown-alert.markdown-alert-caution .markdown-alert-title {
color: var(--color-caution);
}
lsw-store
Gestor de estado para navegador y node.js.
Branch from @allnulled/universal-store.
Instalación
Descargar la librería
npm install -s @allnulled/universal-store
Importar la librería
Modos de importar la librería
Dado que usa otras librerías, y pueden quererse usar desde otros módulos o no, puedes usar el archivo:
-
store.js: este fichero tiene todas las APIs necesarias. Incluye:
-
store.unbundled.js: este fichero solo tiene la parte que le es propia, y sobreentiende que cargarás las otras librerías necesarias por tu propia cuenta.
NOTA: Por defecto, se usa store.unbundled.js.
En node.js
Puedes usar require o import indistintamente para importar el módulo.
En browser
<script src="node_modules/@allnulled/universal-store/dist/store.js"></script>
O alternativamente:
<script src="node_modules/@allnulled/universal-store/dist/lib/ufs.js"></script>
<script src="node_modules/@allnulled/universal-store/dist/store.unbundled.js"></script>
API
Crear una store
Para crear una store, desde node.js puedes:
const store = require("@allnulled/universal-store").create();
Si estás en browser y no usas módulos, o si estás en node.js y no quieres usar require, puedes:
const store = UniversalStore.create();
Usar una store
Los métodos de la API disponibles por defecto son:
store.get("property/id");
store.set("property/id", 1);
store.watch("property/id", function(event, property_path, value) {});
store.unwatch("property/id", previous_function);
store.delete("property/id");
store.push("property/id/to/array", 1);
store.pop("property/id/to/array");
store.unshift("property/id/to/array", 1);
store.shift("property/id/to/array");
store.add("property/id/to/object", "key", 1);
store.remove("property/id/to/object", "key");
store.splice("property/id/to/array", 5, 10, ...[1, 1, 1]);
store.extend("property/id/to/object", { more: "props" });
store.modify("property/id", function(value) { return "new value"; });
store.hydrate("file_to_read_from.json");
store.dehydrate("file_to_write_to.json");
Todos son métodos síncronos y no tienen alternativa.
Los métodos hydrate y dehydrate están polyfileados con la librería ufs o universal-file-system, de allnulled también. Así que puedes persistir el estado del store tanto en node.js como en el browser.