Skip to content
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

How does $prop work? #1

Open
nickchomey opened this issue Jan 23, 2025 · 2 comments
Open

How does $prop work? #1

nickchomey opened this issue Jan 23, 2025 · 2 comments

Comments

@nickchomey
Copy link

nickchomey commented Jan 23, 2025

Thanks for this great library!

It's not clear to me how $prop works. For example, in this modified example from the Readme:

import { deepSignal } from 'alien-deepsignals';
const state = deepSignal({
  count: 0,
  name: "John",
  nested: {
    deep: "value",
  },
  array: [1, 2, 3],
});
effect(() => console.log(state.nested.deep)); //value
state.$nested.value.deep = "new value"; //new value
state.nested.deep = "new value2"; //new value2

What is the difference between the last two lines? They seem to have the same result.

Except i get this error from Deno for the state.$nested line: 'state.$nested' is possibly 'undefined'.deno-ts(18048)

Thanks!

@nickchomey
Copy link
Author

nickchomey commented Jan 23, 2025

Ah, the error is explained here in the original deepsignal readme.

I'm still curious about the original question though: what does $prop do? Its still not clear to me from reading that original readme

@CCherry07
Copy link
Owner

Ah, the error is explained here in the original deepsignal readme.

I'm still curious about the original question though: what does $prop do? Its still not clear to me from reading that original readme

$prop gets the signal object, and .value gets its value.

const state = deepSignal({
  count: 0,
  name: "John",
  nested: {
    deep: "value",
  },
  array: [1, 2, 3],
});

state.$count.value =  2 // What is obtained is the signal of the path of count.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants