Skip to content

Commit

Permalink
Initial commit of code
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed May 30, 2015
1 parent d010a06 commit d8db900
Show file tree
Hide file tree
Showing 19 changed files with 958 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

.idea
6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.idea/
/node_modules/
/lib/haro.min.js
/lib/haro.min.js.map
/src/
/test/
.git
.gitignore
.travis.yml
CHANGELOG.md
Gruntfile.js
89 changes: 89 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module.exports = function (grunt) {
grunt.initConfig({
pkg : grunt.file.readJSON("package.json"),
concat: {
options : {
banner : "/**\n" +
" * <%= pkg.description %>\n" +
" *\n" +
" * @author <%= pkg.author %>\n" +
" * @copyright <%= grunt.template.today('yyyy') %> <%= pkg.author.name %>\n" +
" * @license <%= pkg.license %>\n" +
" * @link <%= pkg.homepage %>\n" +
" * @version <%= pkg.version %>\n" +
" */\n"
},
dist: {
src : [
"src/intro.js",
"src/clone.js",
"src/deferred.js",
"src/merge.js",
"src/uuid.js",
"src/haro.js",
"src/factory.js",
"src/outro.js"
],
dest : "lib/<%= pkg.name %>.es6.js"
}
},
babel: {
options: {
sourceMap: false
},
dist: {
files: {
"lib/<%= pkg.name %>.js": "lib/<%= pkg.name %>.es6.js"
}
}
},
nodeunit : {
all : ["test/*.js"]
},
sed : {
"version" : {
pattern : "{{VERSION}}",
replacement : "<%= pkg.version %>",
path : ["<%= concat.dist.dest %>"]
}
},
uglify: {
options: {
banner: '/* <%= grunt.template.today("yyyy") %> <%= pkg.author %> */\n',
sourceMap: true,
sourceMapIncludeSources: true,
mangle: {
except: ["Tuple"]
}
},
target: {
files: {
"lib/<%= pkg.name %>.min.js" : ["lib/<%= pkg.name %>.js"]
}
}
},
watch : {
js : {
files : "<%= concat.dist.src %>",
tasks : "default"
},
pkg: {
files : "package.json",
tasks : "default"
}
}
});

// tasks
grunt.loadNpmTasks("grunt-sed");
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-nodeunit");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-uglify");
grunt.loadNpmTasks("grunt-babel");

// aliases
grunt.registerTask("test", [/*"nodeunit"*/]);
grunt.registerTask("build", ["concat", "sed", "babel", "uglify"]);
grunt.registerTask("default", ["build", "test"]);
};
86 changes: 85 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,86 @@
# haro
Harō is modern DataStore that can be wired to an API
Harō is modern DataStore that can be wired to an API, & provides a simple feedback loop with `Promises`!

[![build status](https://secure.travis-ci.org/avoidwork/haro.svg)](http://travis-ci.org/avoidwork/haro)

### Example
```javascript
var store = haro();

store.set(null, {abc: true}).then(function (arg) {
console.log(arg); // ["ae3b34bd-8725-43e6-98a8-bf783bae6d71", {abc: true}];
});
```

### Configuration
_config_
Object

Default settings for `fetch()`. You must manually enable `CORS` mode!

_key_
String

Optional `Object` key to utilize as `Map` key, defaults to a version 4 `UUID` if not specified, or found

_source_
String

Optional `Object` key to retrieve data from API responses, see `setUri()`

### Properties
_total_
Number

Total records in the DataStore

_uri_
String

URI of an API the DataStore is wired to, in a feedback loop (do not modify, use `setUri()`)

### API
_batch( array, type )_
Promise

The first argument must be an `Array`, and the second argument must be `del` or `set`

_del( key )_
Promise

Deletes the record

_get( key )_
Tuple

Gets the record as a double `Tuple` with the shape `[key, data]`

_range( start, end )_
Tuple

Gets a `Tuple` of double `Tuples` with the shape `[key, data]` for the corresponding range of records

_request( input, config )_
Promise

Returns a `Promise` for a `fetch()` with a coerced response body (JSON or text) as the `resolve()` argument

_set( key, data, batch=false )_
Promise

Returns a `Promise` for setting/amending a record in the DataStore, if `key` is `false` a version 4 `UUID` will be generated

_setUri( uri )_
Promise

Returns a `Promise` for wiring the DataStore to an API, with the retrieved record set as the `resolve()` argument

### Requirements
- `Map`
- `Promise`
- `fetch()`
- `tuple()` see [tiny-tuple](https://github.com/avoidwork/tiny-tuple) for loading in a browser

## License
Copyright (c) 2015 Jason Mulligan
Licensed under the BSD-3 license
Loading

0 comments on commit d8db900

Please sign in to comment.