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

Observable object #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zdenko
Copy link

@zdenko zdenko commented Feb 24, 2018

While working on a project of mine I added a few methods for the observable object, which I find useful.

Proxy object properties:

obj = Observable 
  a: 1

assert.equal obj.a, obj().a

obj.a = 2
assert.equal obj.a, obj().a

Observable properties:

obj = Observable 
  a: Observable 1

assert.equal obj.a, obj().a()

obj.a 2
assert.equal obj.a, 2
assert.equal obj().a(), 2

obj.a = 3
assert.equal obj.a, 3
assert.equal obj().a(), 3

Extend method:

obj = Observable 
  a: 1

obj.extend b: 2   # alias: obj.assign b: 2
assert.equal obj.b, 2
assert.equal obj.b, obj().b

Remove method:

obj = Observable 
  a: 1
  b: 2

obj.remove "b"
assert.equal obj.b, undefined

Proxy object methods:

obj = Observable 
  a: 1
  b: 2

assert.deepEqual obj.keys, ["a", "b"]
assert.deepEqual obj.values, [1, 2]
assert.deepEqual obj.entries, [["a", 1], ["b", 2]]

@STRd6
Copy link
Contributor

STRd6 commented Feb 24, 2018

Thanks for this contribution! It does seem useful, I'll have to think on it a while and work through the implications.

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

Successfully merging this pull request may close these issues.

2 participants