Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
d0167fab
authored
2013-07-21 17:38:23 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add initial Rivets.adapters (Default adapter for ES5 POJSOs). [#178]
1 parent
11cfcf17
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
src/rivets.coffee
src/rivets.coffee
View file @
d0167fa
...
...
@@ -682,6 +682,49 @@ Rivets.components = {}
# instance.
Rivets
.
formatters
=
{}
# Rivets.adapters
# -----------------
# Default adapters (`.` for POJSO in ES5 natives), publicly accessible on
# `module.adapters`. Can be overridden globally or local to a `Rivets.View`
# instance.
Rivets
.
adapters
=
'.'
:
id
:
'_rv'
counter
:
0
weakmap
:
{}
subscribe
:
(
obj
,
keypath
,
callback
)
->
unless
obj
[
@
id
]
?
obj
[
@
id
]
=
@
counter
++
@
weakmap
[
obj
[
@
id
]]
=
{}
map
=
@
weakmap
[
obj
[
@
id
]]
unless
map
[
keypath
]
?
map
[
keypath
]
=
[]
value
=
obj
[
keypath
]
Object
.
defineProperty
obj
,
keypath
,
get
:
->
value
set
:
(
newValue
)
->
if
newValue
isnt
value
value
=
newValue
callback
()
for
callback
in
map
[
keypath
]
unless
callback
in
map
[
keypath
]
map
[
keypath
].
push
callback
unsubscribe
:
(
obj
,
keypath
,
callback
)
->
callbacks
=
@
weakmap
[
obj
[
@
id
]][
keypath
]
callbacks
.
splice
callbacks
.
indexOf
(
callback
),
1
read
:
(
obj
,
keypath
)
->
obj
[
keypath
]
publish
:
(
obj
,
keypath
,
value
)
->
obj
[
keypath
]
=
value
# Rivets.config
# -------------
...
...
@@ -709,6 +752,9 @@ Rivets.factory = (exports) ->
# Exposes the formatters object to be extended.
exports
.
formatters
=
Rivets
.
formatters
# Exposes the adapters object to be extended.
exports
.
adapters
=
Rivets
.
adapters
# Exposes the rivets configuration options. These can be set manually or from
# rivets.configure with an object literal.
exports
.
config
=
Rivets
.
config
...
...
Please
register
or
sign in
to post a comment