-
Notifications
You must be signed in to change notification settings - Fork 4
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
0 parents
commit f156e31
Showing
12 changed files
with
350 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,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,4 @@ | ||
node_modules | ||
.idea/ | ||
*.log | ||
.DS_Store |
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,21 @@ | ||
{ | ||
"node": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"indent": 4, | ||
"latedef": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"quotmark": "single", | ||
"regexp": true, | ||
"undef": true, | ||
"unused": true, | ||
"strict": true, | ||
"trailing": true, | ||
"smarttabs": true, | ||
"white": true | ||
} |
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,9 @@ | ||
npm-debug.log | ||
node_modules | ||
example | ||
docs | ||
.idea | ||
|
||
|
||
# don't ignore .npmignore files | ||
!.npmignore |
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,5 @@ | ||
language: node_js | ||
node_js: | ||
- 0.10 | ||
before_script: | ||
- npm install -g gulp |
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,4 @@ | ||
v0.1.0: | ||
date: 2014-6-9 | ||
changes: | ||
- Initial release. |
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,45 @@ | ||
/* | ||
* virtual-dom-component | ||
* https://github.com/alexmingoia/virtual-dom-component | ||
* | ||
* Copyright (c) 2014 Alex Mingoia <[email protected]> | ||
* Licensed under the BSD license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var gulp = require('gulp'); | ||
var jshint = require('gulp-jshint'); | ||
var mocha = require('gulp-mocha'); | ||
var stylish = require('jshint-stylish'); | ||
|
||
gulp.task('jshint', function () { | ||
// Minify and copy all JavaScript (except vendor scripts) | ||
return gulp.src(['./lib/**/*.js', './test/**/*.js']) | ||
.pipe(jshint()) | ||
.pipe(jshint.reporter(stylish)); | ||
}); | ||
|
||
// Copy all static images | ||
gulp.task('mocha', function () { | ||
return gulp.src('./test/*.js') | ||
.pipe(mocha({ | ||
globals: ['chai'], | ||
timeout: 6000, | ||
ignoreLeaks: false, | ||
ui: 'bdd', | ||
reporter: 'spec' | ||
})); | ||
}); | ||
|
||
// Rerun the task when a file changes | ||
gulp.task('watch', function () { | ||
gulp.watch(['./lib/**/*.js', './test/**/*.js'], ['jshint']); | ||
}); | ||
|
||
gulp.task('test', function () { | ||
gulp.run('mocha', function () {}); | ||
}); | ||
|
||
// The default task (called when you run `gulp` from cli) | ||
gulp.task('default', ['jshint', 'mocha', 'watch']); |
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,30 @@ | ||
The BSD License | ||
|
||
Copyright (c) 2014, Alex Mingoia <[email protected]> | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
|
||
* Neither the name of the Alex Mingoia <[email protected]> nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,99 @@ | ||
# virtual-dom-component [](http://travis-ci.org/alexmingoia/virtual-dom-component) [](http://badges.enytc.com/for/npm/virtual-dom-component) [](https://bitdeli.com/free "Bitdeli Badge") | ||
|
||
> A virtual DOM component (view). | ||
Virtual components are a thin wrapper around a render method which takes the | ||
state and returns a virtual DOM representation. | ||
|
||
## Getting Started | ||
|
||
Install the module with: `npm install virtual-dom-component` | ||
|
||
## Usage | ||
|
||
```javascript | ||
var VirtualComponent = require('virtual-dom-component'); | ||
var h = require('virtual-hyperscript'); | ||
|
||
var Profile = VirtualComponent(function(state) { | ||
return h('div', null, | ||
h('h1', null, state.name), | ||
h('img', { src: state.avatarURL }) | ||
); | ||
}); | ||
|
||
// with local state | ||
var Profile = VirtualComponent({ | ||
locals: { | ||
fullName: function(first, last) { | ||
return [first, last].join(' '); | ||
}, | ||
url: function(gid) { | ||
return 'https://gravatar.com/' + gid; | ||
} | ||
}, | ||
render: function(state) { | ||
return h('div', null, | ||
h('h1', null, state.name)), | ||
h('img', { src: this.url(state.gid) }) | ||
); | ||
} | ||
}); | ||
|
||
// using JSX | ||
var Profile = VirtualComponent(function(state) { | ||
return <div> | ||
<h1>{state.name}</h1> | ||
<img src={state.avatarURL } /> | ||
</div>; | ||
}); | ||
|
||
// using constructor and instance | ||
var Profile = new VirtualComponent({ | ||
render: function(state) { | ||
// ... | ||
} | ||
}); | ||
|
||
var vNode = Profile.render(state); | ||
``` | ||
|
||
## Contributing | ||
|
||
Please submit all issues and pull requests to the [alexmingoia/virtual-dom-component](http://github.com/alexmingoia/virtual-dom-component) repository! | ||
|
||
## Support | ||
If you have any problem or suggestion please open an issue [here](https://github.com/alexmingoia/virtual-dom-component/issues). | ||
|
||
## License | ||
|
||
The BSD License | ||
|
||
Copyright (c) 2014, Alex Mingoia <[email protected]> | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, | ||
are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, this | ||
list of conditions and the following disclaimer in the documentation and/or | ||
other materials provided with the distribution. | ||
|
||
* Neither the name of the Alex Mingoia <[email protected]> nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | ||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,49 @@ | ||
/*! | ||
* virtual-dom-component | ||
* https://github.com/alexmingoia/virtual-dom-component | ||
* | ||
* Copyright (c) 2014 Alex Mingoia <[email protected]> | ||
* Licensed under the BSD license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = VirtualComponent; | ||
|
||
/** | ||
* Create new virtual component. | ||
* | ||
* @param {Object=} options | ||
* @param {Object=} options.locals properties and methods local to render(). | ||
* @param {Function} render receives state and returns virtual dom. | ||
* @return {VirtualComponent|Function} | ||
* @api public | ||
*/ | ||
|
||
function VirtualComponent(options, render) { | ||
if (!(this instanceof VirtualComponent)) { | ||
var component = new VirtualComponent(options, render); | ||
|
||
return function render () { | ||
return component.options.render.apply(component.locals, arguments); | ||
}; | ||
} | ||
|
||
if (typeof options === 'function') { | ||
render = options; | ||
options = {}; | ||
} | ||
|
||
options.render = options.render || render; | ||
|
||
if (!options.render) { | ||
throw new Error("VirtualComponent must have a render() method."); | ||
} | ||
|
||
this.options = options; | ||
this.locals = options.locals || {}; | ||
}; | ||
|
||
VirtualComponent.prototype.render = function() { | ||
this.options.render.apply(this.locals, arguments); | ||
}; |
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,41 @@ | ||
{ | ||
"name": "virtual-dom-component", | ||
"description": "A virtual component (view). Virtual components are a thin wrapper around a render method which takes the state and returns a virtual DOM representation.", | ||
"version": "0.1.0", | ||
"homepage": "https://github.com/alexmingoia/virtual-dom-component", | ||
"author": { | ||
"name": "Alex Mingoia", | ||
"email": "[email protected]" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/alexmingoia/virtual-dom-component.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/alexmingoia/virtual-dom-component/issues" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "BSD", | ||
"url": "https://github.com/alexmingoia/virtual-dom-component/blob/master/LICENSE" | ||
} | ||
], | ||
"main": "lib/virtual-dom-component", | ||
"engines": { | ||
"node": ">= 0.10.26", | ||
"npm": ">=1.4.3" | ||
}, | ||
"scripts": { | ||
"test": "gulp test" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "~1.10.0", | ||
"chai": "~1.8.0", | ||
"gulp": "~3.5.0", | ||
"gulp-jshint": "~1.3.4", | ||
"gulp-mocha": "~0.4.1", | ||
"jshint-stylish": "~0.1.5" | ||
}, | ||
"keywords": [] | ||
} |
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,30 @@ | ||
/* | ||
* virtual-dom-component | ||
* https://github.com/alexmingoia/virtual-dom-component | ||
* | ||
* Copyright (c) 2014 Alex Mingoia <[email protected]> | ||
* Licensed under the BSD license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
|
||
var VirtualComponent = require('../lib/virtual-dom-component.js'); | ||
|
||
describe('virtual-dom-component module', function(){ | ||
describe('VirtualComponent()', function(){ | ||
it('should return render function', function(){ | ||
var render = VirtualComponent({ render: function(){} }); | ||
expect(render).to.be.a('function'); | ||
}); | ||
|
||
it('instantiates component', function() { | ||
var component = new VirtualComponent(function() {}); | ||
expect(component).to.be.an('object'); | ||
expect(component).to.have.property('options'); | ||
expect(component).to.have.property('render'); | ||
}); | ||
}); | ||
}); |