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

Add API for getting the value of an observation #130

Closed
chasenlehara opened this issue Apr 25, 2018 · 1 comment
Closed

Add API for getting the value of an observation #130

chasenlehara opened this issue Apr 25, 2018 · 1 comment

Comments

@chasenlehara
Copy link
Member

Right now you can use can-reflect to get the value of an observation, but it’d be nice if there was a more simple API for doing that. Related, some observables build on top of can-observation and make it possible to set values; a consistent, friendly API for both getting and setting values would be nice.

Two options stick out to me:

  1. Document get() and suggest that other observables implement a set() method. That would look something like:
import Observation from "can-observation";
import keyObservable from "can-simple-observable/key/key";

const observation = new Observation(() => 15);
observation.get(); // -> 15

const observable = keyObservable(/* ... */);
observable.set(22);
observable.get(); // -> 22
  1. Create a configurable value property on observations:
import Observation from "can-observation";
import keyObservable from "can-simple-observable/key/key";

const observation = new Observation(() => 15);
observation.value; // -> 15

const observable = keyObservable(/* ... */);
observable.value = 22;
observable.value; // -> 22
@chasenlehara
Copy link
Member Author

I’m going to go with option 2, creating a value property on observations.

chasenlehara added a commit that referenced this issue Jul 2, 2018
This adds an API for getting the value of an observation by replacing the old internal `value` property with `_value` and adding a new `value` getter so the following works:

```js
import Observation from "can-observation";

const observation = new Observation(() => 15);
observation.value; // is 15
```

Closes #130
chasenlehara added a commit that referenced this issue Jul 2, 2018
This adds an API for getting the value of an observation by replacing the old internal `value` property with `_value` and adding a new `value` getter so the following works:

```js
import Observation from "can-observation";

const observation = new Observation(() => 15);
observation.value; // is 15
```

Closes #130
chasenlehara added a commit to canjs/can-simple-observable that referenced this issue Jul 3, 2018
This adds an API for getting & setting the value of the observation returned by the key module:

```js
import keyObservable from "can-simple-observable/key/key";

const outer = {inner: {key: "hello"}};
const observable = keyObservable(outer, "inner.key");

observable.value; // is "hello"

observable.value = "goodbye";
observable.value; // is now "goodbye"
```

Related to canjs/can-observation#130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant