Nickolay - KiokuJS.Backend.Batch-0.01
Name
KiokuJS.Backend.Batch - Some clever yet compact description
SYNOPSIS
// declaring our class
Class('KiokuJS.Backend.Batch', {
})
// then instantiating it
var instance = new KiokuJS.Backend.Batch({
})
// and doing something totally awesome with it :D
instance.method(param1, param2)
DESCRIPTION
KiokuJS.Backend.Batch
is a stub for Joose-orientied JSAN modules.
ISA
None.
DOES
None.
TRAITS
None.
ATTRIBUTES
attributeName
AttributeType attributeName
Attribute description
METHODS
methodName
method signature
Method description
EXAMPLES
Our class can be used like this:
// then instantiating it
var instance = new KiokuJS.Backend.Batch({
})
and like that:
// then instantiating it
var instance = new KiokuJS.Backend.Batch({
})
GETTING HELP
This extension is supported via github issues tracker: http://github.com/SamuraiJack/KiokuJS-Backend-Batch/issues
For general Joose questions you can also visit #joose on irc.freenode.org or mailing list at: http://groups.google.com/group/joose-js
SEE ALSO
Web page of this module: http://github.com/SamuraiJack/KiokuJS-Backend-Batch/
General documentation for Joose: http://openjsan.org/go/?l=Joose
BUGS
All complex software has bugs lurking in it, and this module is no exception.
Please report any bugs through the web interface at http://github.com/SamuraiJack/KiokuJS-Backend-Batch/issues
AUTHORS
Nickolay Platonov nplatonov@cpan.org
COPYRIGHT AND LICENSE
This software is Copyright (c) 2010 by Nickolay Platonov.
This is free software, licensed under:
The GNU Lesser General Public License, Version 3, June 2007
Role('KiokuJS.Backend.Batch', { /*VERSION*/VERSION : 0.01, requires : [ 'serialize', 'deserialize', 'get', 'insert', 'remove', 'exists' ], trait : 'JooseX.CPS', has : { baseURL : { is : 'rw', init : '/index.html' } }, use : [ Joose.is_NodeJS ? 'HTTP.Request.Provider.NodeJS' : 'HTTP.Request.Provider.XHR', 'KiokuJS.Exception.Format', 'KiokuJS.Exception.Network', 'KiokuJS.Exception.LookUp', 'KiokuJS.Exception.Overwrite', 'KiokuJS.Exception.Update', 'KiokuJS.Exception.Conflict' ], methods : { getRequest : function (config) { config.headers = { 'content-type' : 'application/json' } return new HTTP.Request.Provider.getRequest(config) }, getURLfor : function (action) { return this.getBaseURL() + '/index.html' + action }, decodeException : function (packet) { return this.decodePacket(packet)[ 0 ].error } }, continued : { override : { get : function (idsToGet, mode) { if (!idsToGet.length) { this.CONTINUE([]) return } var req = this.getRequest({ method : 'PUT', data : this.serializer.serialize(idsToGet) }) req.request(this.getURLfor('get')).except(function (e) { throw new KiokuJS.Exception.Network({ nativeEx : e }) }).andThen(function (res) { var response = this.deserialize(res.text) if (response.error) throw this.decodeException(response.error) else this.CONTINUE(response.result) }, this) }, insert : function (entries, mode) { if (!entries.length) { this.CONTINUE([]) return } var data = this.serialize({ entries : entries, mode : mode }) var req = this.getRequest({ method : 'PUT', data : data }) req.request(this.getURLfor('insert')).except(function (e) { throw new KiokuJS.Exception.Network({ nativeEx : e }) }).andThen(function (res) { var response = this.deserialize(res.text) if (response.error) throw this.decodeException(response.error) else this.CONTINUE(response.result) }, this) }, remove : function (entriesOrIds) { if (!entriesOrIds.length) { this.CONTINUE() return } var ids = Joose.A.map(entriesOrIds, function (entryOrId) { if (entryOrId === Object(entryOrId)) { var copy = Joose.O.copy(entryOrId) delete copy.data return copy } return entryOrId }) var req = this.getRequest({ method : 'PUT', data : this.serialize(ids) }) req.request(this.getURLfor('remove')).except(function (e) { throw new KiokuJS.Exception.Network({ nativeEx : e }) }).andThen(function (res) { var response = this.deserialize(res.text) if (response.error) throw this.decodeException(response.error) else this.CONTINUE(response.result) }, this) }, exists : function (idsToCheck) { if (!idsToCheck.length) { this.CONTINUE([]) return } var req = this.getRequest({ method : 'PUT', data : this.serialize(idsToCheck) }) req.request(this.getURLfor('exists')).except(function (e) { throw new KiokuJS.Exception.Network({ nativeEx : e }) }).andThen(function (res) { var response = this.deserialize(res.text) if (response.error) throw this.decodeException(response.error) else this.CONTINUE(response.result) }, this) } } } })