Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asciidisco committed Nov 12, 2012
1 parent 0552b2c commit e7b1c9c
Show file tree
Hide file tree
Showing 8 changed files with 192 additions and 149 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
docs/
docs/
node_modules/
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ node_js:
before_script:
- "git submodule update --init"
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- "phantomjs bin/phantomjs.js"
- "nodelint src/backbone.rpc.js"
- "grunt travis --verbose"
55 changes: 0 additions & 55 deletions Cakefile

This file was deleted.

64 changes: 29 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Backbone.Rpc
Plugin for using the backbone js library with json-rpc instead of the native REST implementation
Plugin for using the backbone js library with json-rpc instead of the native REST implementation

## Build Status, Project Page, Annotated Source & Tests
[![Build Status](https://secure.travis-ci.org/asciidisco/Backbone.Rpc.png?branch=master)](http://travis-ci.org/asciidisco/Backbone.Rpc)<br /><br />
Expand All @@ -25,7 +25,7 @@ vanilla javascript.

The plugin itself has three dependencies, underscore.js, jQuery and backbone.js

You can directly download the
You can directly download the
[Development Version](https://raw.github.com/asciidisco/Backbone.Rpc/master/backbone.rpc.js)
or the
[Production Version](https://raw.github.com/asciidisco/Backbone.Rpc/master/backbone.rpc.min.js)
Expand Down Expand Up @@ -188,7 +188,7 @@ deviceModel.fetch(); // Calls 'read'
// Request created by the 'read' call
{"jsonrpc":"2.0","method":"getFilteredDevicesById","id":"1331724849298","params":["14"]}:
```
Hopefully you noticed that the contents of the 'id' attribute are applied as part of the
Hopefully you noticed that the contents of the 'id' attribute are applied as part of the
params array in the response.

As seen in the update call, you can add as many as params as you like:
Expand All @@ -197,7 +197,7 @@ As seen in the update call, you can add as many as params as you like:
update: ['setDeviceName', 'id', 'name']
```

### Fire multiple RPC calls with one method call
### Fire multiple RPC calls with one method call
Sometimes we need to do more then one remote method call when we operate on an entity.
Using our device example, we can say that every time a device will be created we need
to reset the server side device cache.
Expand All @@ -213,7 +213,7 @@ var DeviceModel = Backbone.Model.extend({
methods: {
// ...
create: [
['addDevice', 'name'],
['addDevice', 'name'],
['invalidateCache']
]
// ...
Expand Down Expand Up @@ -307,7 +307,7 @@ var DeviceModel = Backbone.Model.extend({
var deviceModelThree = new DeviceModel();
deviceModel.set({id: 10, roomId: 12});
deviceModel.addDeviceToRoom({success: function () {
deviceModel.get('roomName'); // 'Living Room'
deviceModel.get('roomName'); // 'Living Room'
}});

```
Expand All @@ -330,6 +330,18 @@ var devices = new Devices();
devices.fetch();
```

### Content-Type
The default content type of requests is 'application/json'
You can override it like this:

```javascript
// ...
rpc: new Backbone.Rpc({
contentType: 'application/json'
})
//...
```

### Namespaces
Most of the time, you´re in need to call methods within a namespace.
No worries, we thought of that too.
Expand Down Expand Up @@ -360,7 +372,7 @@ var TextModel = Backbone.Model.extend({
namespace: 'MySuperEnterprisyNamespace',
url: 'path/to/my/rpc/handler',
rpc: new Backbone.Rpc({
namespaceSeparator: '::'
namespaceDelimiter: '::'
}),
methods: {
read: ['getRandomTextSnippet']
Expand All @@ -377,7 +389,7 @@ textModel.fetch();

Nice, hah?!

### Exceptions
### Exceptions
When working with a JSON RPC Service you can encounter different types of errors.
The default error handler simply throws if something bad happens.

Expand Down Expand Up @@ -411,35 +423,17 @@ var TextModel = Backbone.Model.extend({
});
```

## TODO

+ Add more inline documentation
+ Add more unit tests (edge cases)
+ Increase stability of the build process (Windows)
+ More real world browser tests
+ Add API Docs
+ Clean up code
+ Include JSLint in the CI and build process
+ FIX TYPOS!!!

## Changelog

-

## Build on the shoulder of giants
Thanks to all the great people behind the following projects,
who helped me with developing this one:

[jQuery](http://jquery.com)<br />
[backbone](http://backbonejs.org/)<br />
[underscore](http://underscorejs.org/)<br />
[PhantomJS](http://www.phantomjs.org/)<br />
[Travis CI](http://travis-ci.org/)<br />
[QUnit](http://docs.jquery.com/QUnit)<br />
[Sinon](http://sinonjs.org/)<br />
[Cake](http://coffeescript.org/)<br />
[Uglify](https://github.com/mishoo/UglifyJS)<br />
[DocumentUp](http://documentup.com/)
### 0.1.1
+ Switch build system from cake to grunt
+ Cleaned up
+ Fixed #3 - Content type defaults to 'application/json' & can now be overriden
+ Fixed #5 - README fixes & improvments
+ Inline doc improvements

### 0.1.0
+ Initial Release

## License
Copyright (c) Sebastian Golasch ([@asciidisco](https://twitter.com/#!/asciidisco)) 2012
Expand Down
24 changes: 11 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
{
"name": "Backbone.Rpc",
"version": "0.1.0",
"version": "0.1.1",
"description": "Plugin for using backbone js with json-rpc instead of the native REST implementation",
"homepage": "http://asciidisco.github.com/Backbone.Rpc/index.html",
"keywords": ["backbone", "plugin", "rpc", "json", "client", "browser"],
"repository": {"type": "git", "url": "git://github.com/asciidisco/Backbone.Rpc.git"},
"author" : "Sebastian Golasch <public@asciidisco.com>",
"repository": {"type": "git", "url": "git://github.com/asciidisco/Backbone.Rpc.git"},
"author" : "Sebastian Golasch <public@asciidisco.com>",
"maintainers": [
{
"name": "Sebastian Golasch (asciidisco)",
"email": "public@asciidisco.com",
"web": "http://asciidisco.com"
"web": "http://asciidisco.com"
}
],
"licenses": [{ "type": "MIT", "url": "http://mit-license.org/" }],
"repositories": [{ "type": "git", "url": "https://github.com/asciidisco/Backbone.Rpc" }],
"lib": ".",
"main": "backbone.rpc.js",
"devDependencies": {
"qunit": ">=0.2.x",
"sinon": ">=1.3.x",
"nodelint": ">=0.x.x",
"docco": ">=0.x.x",
"coffee-script": ">=0.x.x"
"devDependencies": {
"qunit": "0.2.x",
"sinon": "1.3.x",
"grunt": "0.3.x"
},
"dependencies" : {
"underscore" : ">=1.3.1",
"backbone": ">=0.9.x",
"jquery": ">=1.6.x"
"underscore" : "1.3.x",
"backbone": "0.9.x",
"jquery": "1.6.x"
}
}
28 changes: 16 additions & 12 deletions src/backbone.rpc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*jslint nomen: true, unparam: true, indent: 4, maxlen: 160, es5: false */
// Backbone.Rpc
// Plugin for using the backbone js library with a remote json-rpc handler
// instead of the default REST one
Expand All @@ -12,11 +11,11 @@
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['underscore', 'backbone', 'jquery'], function (_, Backbone, $) {
// Check if
// Check if
_ = _ === undef ? root._ : _;
Backbone = Backbone === undef ? root.Backbone : Backbone;
$ = $ === undef ? root.$ : $;
return (root.returnExportsGlobal = factory(_, Backbone, $));
return (root.Backbone = factory(_, Backbone, $));
});
} else {
// Browser globals
Expand All @@ -29,6 +28,8 @@
this.options = options !== undef ? options : {};
// check if we have a non std. namespace delimter
this.namespaceDelimiter = options !== undef && options.namespaceDelimiter !== undef ? options.namespaceDelimiter : this.namespaceDelimiter;
// check if we have a non std. content-type
this.contentType = options !== undef && options.contentType !== undef ? options.contentType : this.contentType;
// fix issue with the loss of this
_.bindAll(this);
},
Expand All @@ -41,22 +42,25 @@

// TODO: Document
Rpc.prototype = {
// TODO: Document
// User defined options placeholder
options: {},

// TODO: Document
// Default charset
charset: 'iso-8859-1',

// TODO: Document
// Default namespace
namespace: '',

// TODO: Document
// Default namespace delimiter
namespaceDelimiter: '/',

// TODO: Document
// Default content type
contentType: 'application/json',

// User set url placeholder
url: null,

// TODO: Document
// Server response id
responseID: null,

// TODO: Document
Expand Down Expand Up @@ -121,7 +125,7 @@
if (_.isArray(params) && _.isString(fn)) {
// send query
ret = $.ajax({
contentType : 'application/x-www-form-urlencoded; charset=' + this.charset,
contentType : this.contentType + '; charset=' + this.charset,
type : 'POST',
dataType : 'json',
url : this.url,
Expand Down Expand Up @@ -279,7 +283,7 @@
constructor: function (model) {
// check if the model has the rpc property and methods defined
if (this.rpc !== undef && _.isFunction(this.rpc.invoke) === true && this.methods !== undef) {
// walk through the methods
// walk through the methods
_.each(this.methods, _.bind(function (method, signature) {
// check if we have a 'non standard' signature
if ({'read': 1, 'create': 1, 'remove': 1, 'update': 1}[signature] !== 1) {
Expand Down Expand Up @@ -336,7 +340,7 @@
storage[data._rpcId] = data;
}

// change data attr to be an empty array, if it´s null or undefined
// change data attr to be an empty array, if it´s null or undefined
if (data === undef || data === null) {
data = [];
}
Expand Down
Loading

0 comments on commit e7b1c9c

Please sign in to comment.