Skip to content
This repository has been archived by the owner on Jul 11, 2018. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vagrant authored and boekkooi committed May 23, 2013
0 parents commit 8cd4051
Show file tree
Hide file tree
Showing 45 changed files with 6,821 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
node_modules/
118 changes: 118 additions & 0 deletions Cakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# # ** Cakefile **#
#
# * build - compiles src directory to lib directory
# * example - updates the example project
# * docs - generates annotated documentation using docco

# Files to compile with coffeescript
files = [
'src'
]

# ANSI Terminal Colors
bold = '\x1b[0;1m'
green = '\x1b[0;32m'
reset = '\x1b[0m'
red = '\x1b[0;31m'

# require the needed modules
fs = require 'fs'
path = require 'path'
{print} = require 'util'
{spawn, exec} = require 'child_process'
try wrench = require 'wrench' catch err
try which = require('which').sync catch err

if !wrench || !which
console.log red + 'WARNING: Missing one of the following modules:'
console.log '* wrench (npm install wrench)' if !wrench
console.log '* which (npm install which)' if !which && process.platform.match(/^win/)?
console.log reset

# Cakefile build output directory option
option '-o', '--output [DIR]', 'directory for compiled code'

# ## *build*
# Builds Source
task 'build', 'compile source', (options) ->
dir = options.output or 'lib'
build dir

# ## *example*
# Update the example project
task 'example', 'compile source and copy it to example project', (options) ->
build 'lib', () ->
exampleDir = path.join('example', 'packages', 'reactive-extra')
exampleLibDir = path.join(exampleDir, 'lib')

wrench.rmdirSyncRecursive exampleDir
wrench.mkdirSyncRecursive exampleLibDir
wrench.copyDirSyncRecursive 'lib', exampleLibDir,
forceDelete: true

fs.writeFileSync path.join(exampleDir, 'package.js'), fs.readFileSync 'package.js'

log 'Let\'s examine the example', green
log 'why don\'t you test it?\ncd example\nmeteor test-packages reactive-extra', bold

# ## *docs*
# Generate Annotated Documentation
task 'docs', 'generate documentation', (options) ->
dir = options.output or 'docs'

tmpDir = path.join dir, '.tmp'
wrench.mkdirSyncRecursive tmpDir

files = wrench.readdirSyncRecursive('src').filter (file) ->
!fs.statSync( path.join('src', file) ).isDirectory();

tmpFiles = files.map (file) ->
path.join tmpDir, file.replace /[\/\\]/g, '_'

for file of files
fs.writeFileSync(tmpFiles[file], fs.readFileSync(path.join('src', files[file])));

options = [ '-l', 'parallel', '-o', dir ]
options = options.concat tmpFiles
launch 'docco', options, () ->
wrench.rmdirSyncRecursive tmpDir
log "Get the api docs while there hot", green

# # Internal Functions

# ## *build*
build = (dir, callback) ->
wrench.mkdirSyncRecursive dir

options = ['-c', '-o', dir]
options = options.concat files
launch 'coffee', options, () ->
if callback
callback()
else
log 'Look mom I created a railroad', green

# ## *launch*
#
# **given** string as a cmd
# **and** optional array and option flags
# **and** optional callback
# **then** spawn cmd with options
# **and** pipe to process stdout and stderr respectively
# **and** on child process exit emit callback if set and status is 0
launch = (cmd, options=[], callback) ->
cmd = which(cmd) if which
app = spawn cmd, options
app.stdout.pipe(process.stdout)
app.stderr.pipe(process.stderr)
app.on 'exit', (status) -> callback?() if status is 0

# ## *log*
#
# **given** string as a message
# **and** string as a color
# **and** optional string as an explanation
# **then** builds a statement and logs to console.
#
log = (message, color, explanation) ->
console.log color + message + reset + ' ' + (explanation or '')
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pyright (c) 2013 Warnar Boekkooi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Meteor Reactive Extra package
This is a [Meteor](http://meteor.com/) package containing reactive classes.
These classes can be used within Meteor to easily create reactive objects, dictionaries and arrays.

## Install

### Meteorite
Using [meteorite](http://oortcloud.github.io/meteorite/) do the following:
```
mrt add reactive-extra
```

### Other
If you don't like using meteorite create the folder `packages/reactive-extra/` and can copy the `packages.js` and `lib/` to it.

## ReactiveObject
A reactive object implementation.
Checkout the [api docs](https://boekkooi.github.io/reactive-extra/reactive-object.html)

### Usage

```javascript
var obj = new ReactiveObject({'foo':'1'});
obj.defineProperty('bar', 2);

obj.foo = '2';
obj.undefineProperty('foo'); // Don't use 'delete obj.foo' it will give strange results
```

## ReactiveDictionary
A reactive dictionary implementation.
Checkout the [api docs](https://boekkooi.github.io/reactive-extra/reactive-dictionary.html)

### Usage

```javascript
var obj = new ReactiveDictionary({'foo':'1'});
obj.add('bar', 2);
obj.count()
obj.foo = '2'
obj.remove('foo'); // Don't use 'delete obj.foo' it will give strange results
obj.clear();
```


## ReactiveArray
A reactive array implementation.
Checkout the [api docs](https://boekkooi.github.io/reactive-extra/reactive-array.html).

### Usage

```javascript
var arr = new ReactiveArray(1,2,3,4);
console.log arr.length
arr.map(function(v) {
return v+1
}).toArray();

// Be aware that using 'arr[9] = "a"' won't work correctly
// A work around is to use 'arr.length = 10' and then do 'arr[9] = "a"'
```

## Cake
The current `cake` commands require the [wrench](https://github.com/ryanmcgrath/wrench-js) module, on windows the [which](https://github.com/isaacs/node-which) module is also required.

### *cake build*
This command will compile the files in `src/` to `lib/`.

### *cake example*
This command will compile the files in `src/` to `lib/`, after which it will copy `packages.js` and `lib/` to `example/packages/reactive-extra`.

### *cake docs*
This command will generate the api docs in `docs/`.
To get it working make sure you have [docco](http://jashkenas.github.io/docco/) installed.

## Todo

* Write a real example not just a placeholder for tests
* Create [Harmony Proxy](http://wiki.ecmascript.org/doku.php?id=harmony:proxies) versions of the classes
* Add `observe` and/or `observeChanges` methods when possible
* Add more test where necessary
Loading

0 comments on commit 8cd4051

Please sign in to comment.