Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
Reorganize linked list logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karthik Viswanathan committed Sep 5, 2012
1 parent 788460b commit 6e0159f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions public/javascripts/views/element.js
Expand Up @@ -149,8 +149,20 @@ define(['jquery', 'backbone', 'underscore', './extended', 'helpers/screen-utils'
var model = this.model;
var previousElement = this.getPreviousElement();

model.set({
head: null,
nextId: null
});

if (previousElement) {
model.set('nextId', previousElement.get('nextId'));
var nextId = previousElement.get('nextId');

if (nextId) {
model.set('nextId', nextId);
} else {
model.set('nextId', null);
}

previousElement.save({ nextId: model.get('id') }, { wait: true });
} else {
// no previous element means this is the head
Expand All @@ -175,7 +187,7 @@ define(['jquery', 'backbone', 'underscore', './extended', 'helpers/screen-utils'

if (nextId) {
// set the previous' nextId to this element's nextId
previousElement.set('nextId', model.get('nextId'));
previousElement.set('nextId', nextId);
} else {
// there is no next; remove the previous' nextId
previousElement.set('nextId', null);
Expand All @@ -190,12 +202,6 @@ define(['jquery', 'backbone', 'underscore', './extended', 'helpers/screen-utils'
nextElement.save({ head: true }, { wait: true });
}
}

// unset the element's nextId and head, but do not save; the element
// will either be deleted promptly (see destroyElement below) or saved
// later (see insertElement)
model.set('nextId', null);
model.set('head', null);
},

destroyElement: function() {
Expand Down

0 comments on commit 6e0159f

Please sign in to comment.