Skip to content

Commit

Permalink
- some progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickolay Platonov committed Oct 6, 2010
1 parent 66cf5f3 commit 8b0c126
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
12 changes: 6 additions & 6 deletions lib/KiokuJS/Backend/Hash.js
Expand Up @@ -39,27 +39,27 @@ Class('KiokuJS.Backend.Hash', {


insert : function (entries, mode) {
var docs = this.docs
var stringifiedEntries = this.serialize(entries)
var docs = this.docs
var strings = this.serialize(entries)

var ids = Joose.A.map(entries, function (entry, index) {

var ID = entry.ID

if (mode == 'insert' && docs[ ID ])
throw new KiokuJS.Exception.Overwrite({
id : id,
id : ID,
oldValue : docs[ ID ],
newValue : stringifiedEntries[ index ]
newValue : strings[ index ]
})

if (mode == 'update' && !docs[ ID ])
throw new KiokuJS.Exception.Update({
message : "Attempt to update entry with ID = [" + ID + "], value = [" + stringifiedEntries[ index ] + "], but no such entry in storage"
message : "Attempt to update entry with ID = [" + ID + "], value = [" + strings[ index ] + "], but no such entry in storage"
})


docs[ ID ] = stringifiedEntries[ index ]
docs[ ID ] = strings[ index ]

return ID
})
Expand Down
22 changes: 9 additions & 13 deletions lib/KiokuJS/Scope.js
Expand Up @@ -338,10 +338,10 @@ Class('KiokuJS.Scope', {
remove : function () {
var me = this

var nodesOrIds = Joose.A.map(arguments, function (arg) {
var entriesOrIds = Joose.A.map(arguments, function (arg) {
// id
// trying to replace an ID with Node where possible, as it has more information attached
if (typeof arg == 'string') return me.idPinned(arg) ? me.idToNode(arg) : arg
// trying to replace an ID with entry where possible, as it has more information attached
if (typeof arg == 'string') return me.idPinned(arg) ? me.idToNode(arg).getEntry() : arg

// object
if (!me.objectPinned(arg))
Expand All @@ -355,15 +355,11 @@ Class('KiokuJS.Scope', {

var backend = this.getBackend()

backend.remove(nodesOrIds).andThen(function () {

Joose.A.each(nodesOrIds, function (nodeOrId) {
// id
if (typeof nodeOrId == 'string')
me.unpinID(nodeOrId)
// node
else
me.unpinNode(nodeOrId)
backend.remove(entriesOrIds).andThen(function () {

Joose.A.each(entriesOrIds, function (entryOrId) {

me.unpinID(typeof entryOrId == 'string' ? entryOrId : entryOrId.ID)
})

this.CONTINUE()
Expand All @@ -376,7 +372,7 @@ Class('KiokuJS.Scope', {

var nodes = {}

Joose.A.each(this.backend.decodeEntries(packet.entries), function (node) {
Joose.A.each(this.decodeEntries(packet.entries), function (node) {
nodes[ node.ID ] = node
})

Expand Down

0 comments on commit 8b0c126

Please sign in to comment.