-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More examples? #42
Comments
Give me some use cases, so will be able to show more scenarios. |
For my use case, I'd like to save a user's shopping cart to the store and then save it to local storage. On reload, I would get from local storage first to populate the store. |
We have a shopping card example here https://github.com/nanostores/nanostores#persistent Do you need information about store update and usage? It is a normal store and you can use as it was described https://github.com/nanostores/nanostores#integration |
I'd like to have more examples for stores testing. |
It would be great to have the classic Todo app as reference. |
I'm personally struggling to understand how the MapTemplate works. The example is brief and leaves me with many questions. For example, it's unclear to me how I to simply add a complex object entry to a MapTemplate store with optional default values, then subscribe to changes of that particular entry. Perhaps this is a shortcoming on my end due to how different the mental model is (I'm coming from a Svelte stores background where I can append to an array or add an entry to an object). I think the examples could cover the wide range of operations and how to use them. |
@fractalhq honestly, I am using it to create some sort of ORM models, and it is a very advanced level of using Nano Stores. Regular apps should use just This is why I am not sure that I will be able to document it in an easy-to-use way. What is your use case? Should we add a note that most users should just use |
I'm having difficulties to understand how to use persistentMap with nanostore actions so I can initialize my persistent store from a fetch. For example, right now I have my store like this
I'm trying to change currentUserState with persistency so I wrote
}); but, if I pass currentuser to the action() method instead of the previous currentUserState , I have an error that says
I don't understand how nanostore and persistency works together. |
Ah ok! I think the README is a bit misleading in initial description:
This makes it seem like the map templates should be used with any array of similar objects. |
Hope these docs changes fix misleading a little bf564db |
Hard agree on the TODO app example. Everything in the README is going over my head :( |
Is it possible to access and manipulate Nanostores data from outside of the component in Lit just like with usual props? Create typical prop in the component: // my-element.ts
@customElement('my-element')
export class MyElement extends LitElement {
@property({type: Number})
aNumber: number = 5;
/* ... */
}
declare global {
interface HTMLElementTagNameMap {
"my-element": MyElement;
}
} Then access and change it's value in the document: // index.html
const myElement = document.createElement('my-element');
myElement.aNumber = 10; The same with Nanostores // stores/counter.ts
import { atom } from 'nanostores'
export const counter = atom(0) // my-element.ts
import { LitElement, css, html } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import { useStores } from "@nanostores/lit"
import { counter } from './stores/counter'
@customElement('my-element')
@useStores(counter)
export class MyElement extends LitElement {
render() {
return html`<div>${counter.get()}</div>`
}
}
declare global {
interface HTMLElementTagNameMap {
"my-element": MyElement;
}
} // index.html
const myElement = document.createElement('my-element');
myElement. // <== How to access Nanostores data here ?? |
You need to access to store: import { counter } from './stores/counter'
counter.set(10) |
@ai thank you for the example but it is not exactly what I need. For example in Lit I can change standard component properties like that by accessing it in the document: <!DOCTYPE html>
<html lang="en">
<head>
<script type="module" crossorigin src="/dist/bundle.js"></script>
</head>
<body>
<my-element></my-element>
<script>
const myElement = document.createElement('my-element');
myElement.counter = 10;
</script>
</body>
</html> Is it possible to do the same with Nanostores? |
There is no built-in method and we do not plan to have it (because it is costly, rare to use, and easy to do manually). For instance, you can do something like: import { counter } from './stores/counter'
globalThis.counter = counter And then: <!DOCTYPE html>
<html lang="en">
<head>
<script type="module" crossorigin src="/dist/bundle.js"></script>
</head>
<body>
<my-element></my-element>
<script>
window.counter.set(10);
</script>
</body>
</html> Or you can check Lit API to add property on a component’s object. |
Hi,
I'm confused as to utilizing nanostores with persistent. Can we get more examples on more complex use cases?
The text was updated successfully, but these errors were encountered: