Skip to content

Commit

Permalink
Create a Page object.
Browse files Browse the repository at this point in the history
See #465.
See #464.
  • Loading branch information
flatheadmill committed Feb 9, 2015
1 parent 2c27500 commit 6d477d6
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions sheaf.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,17 @@ Sheaf.prototype.heft = function (page, s) {
this.magazine.get(page.address).adjustHeft(s)
}

Sheaf.prototype.createLeaf = function (override) {
return this.createPage({
rotation: 0,
loaders: {},
entries: 0,
ghosts: 0,
items: [],
right: { address: 0, key: null },
queue: this.sequester.createQueue()
}, override, 0)
}

Sheaf.prototype.createPage = function (page, override, remainder) {
function Page (sheaf, prototype, override, remainder) {
if (override.address == null) {
while ((this.nextAddress % 2) == remainder) this.nextAddress++
override.address = this.nextAddress++
while (sheaf.nextAddress % 2 == remainder) sheaf.nextAddress++
override.address = sheaf.nextAddress++
}
return extend(page, override)
extend(this, prototype)
extend(this, override || {})
}

Sheaf.prototype.createBranch = function (override) {
return this.createPage({
return new Page(this, {
items: [],
entries: 0,
rotation: 0,
Expand All @@ -100,6 +89,18 @@ Sheaf.prototype.createBranch = function (override) {
}, override, 1)
}

Sheaf.prototype.createLeaf = function (override) {
return new Page(this, {
rotation: 0,
loaders: {},
entries: 0,
ghosts: 0,
items: [],
right: { address: 0, key: null },
queue: this.sequester.createQueue()
}, override, 0)
}

Sheaf.prototype.splice = function (page, offset, length, insert) {
ok(typeof page != 'string', 'page is string')
var items = page.items, heft, removals
Expand Down

0 comments on commit 6d477d6

Please sign in to comment.