-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
220 changed files
with
46,560 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
components | ||
build |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
build: components index.js | ||
@component build --dev | ||
|
||
components: component.json | ||
@component install --dev | ||
|
||
clean: | ||
rm -fr build components template.js | ||
|
||
test: | ||
@./node_modules/.bin/mocha \ | ||
--reporter spec \ | ||
--require should | ||
|
||
.PHONY: clean test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "attr", | ||
"repo": "weepy/attr", | ||
"description": "Simple property with get/set and events", | ||
"version": "0.0.1", | ||
"keywords": [], | ||
"dependencies": { | ||
"component/assert": "*", | ||
"component/emitter": "*" | ||
}, | ||
"development": { | ||
"component/assert": "*" | ||
}, | ||
"license": "MIT", | ||
"scripts": [ | ||
"index.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
var Emitter = require('emitter') | ||
|
||
var methods = { | ||
incr: function (val) { | ||
return this(this.value + (val || 1)) | ||
}, | ||
toggle: function (val) { | ||
return this(!this.value) | ||
}, | ||
change: function(fn) { | ||
if(fn) { | ||
this.on('change', fn) // setup observer | ||
} | ||
else { // force the change | ||
var val = this() | ||
this.emit('change', val, this.old) | ||
} | ||
|
||
return this | ||
}, | ||
toString: function() { | ||
return "attr:"+JSON.stringify(this.value) | ||
} | ||
} | ||
|
||
Emitter(methods) | ||
|
||
|
||
function createAttr(arg) { | ||
function attr(v) { | ||
if(arguments.length) { | ||
attr.old = attr.value | ||
attr.value = v | ||
attr.emit('change', attr.value, attr.old) | ||
} | ||
return attr.value | ||
} | ||
|
||
|
||
for(var i in methods) attr[i] = methods[i] | ||
// set to initial | ||
attr.value = arg | ||
|
||
|
||
return attr | ||
} | ||
|
||
createAttr.computed = function(fn) { | ||
function cattr() { | ||
cattr.old = cattr.value | ||
cattr.value = fn() | ||
cattr.emit('change', cattr.value, cattr.old) | ||
return cattr.value | ||
} | ||
|
||
|
||
for(var i in methods) cattr[i] = methods[i] | ||
|
||
cattr.value = fn() | ||
|
||
// setup dependencies | ||
cattr._depends = [] | ||
|
||
|
||
cattr.depends = function(deps) { | ||
cattr._depends.forEach(function(dep) { | ||
dep.off('change', changeFn) | ||
}) | ||
|
||
cattr._depends = deps | ||
deps.forEach(function(dep) { | ||
dep.on('change', changeFn) | ||
}) | ||
return cattr | ||
} | ||
|
||
function changeFn() { | ||
cattr.change() | ||
} | ||
|
||
return cattr | ||
} | ||
|
||
module.exports = createAttr |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.