Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 39 additions & 44 deletions lib/complexValues/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,31 @@ exports.ObjectValue = ObjectValue
const DescribedObjectValue = DescribedMixin(ObjectValue)
const DeserializedObjectValue = DeserializedMixin(ObjectValue)

const recursorQueue = [
// Prioritize recursing lists
function createListRecursor (desc) {
const replay = recursorUtils.replay(desc.listState, () => desc.createListRecursor())
desc.listState = replay.state
const recursor = replay.recursor
if (recursor === recursorUtils.NOOP_RECURSOR) return [null, null]
return [recursor, stats.describeListRecursor(recursor)]
},
function createPropertyRecursor (desc) {
const replay = recursorUtils.replay(desc.propertyState, () => desc.createPropertyRecursor())
desc.propertyState = replay.state
const recursor = replay.recursor
if (recursor === recursorUtils.NOOP_RECURSOR) return [null, null]
return [recursor, stats.describePropertyRecursor(recursor)]
},
function createIterableRecursor (desc) {
const replay = recursorUtils.replay(desc.iterableState, () => desc.createIterableRecursor())
desc.iterableState = replay.state
const recursor = replay.recursor
if (recursor === recursorUtils.NOOP_RECURSOR) return [null, null]
return [recursor, stats.describeIterableRecursor(recursor)]
},
]

function DescribedMixin (base) {
return class extends base {
constructor (props) {
Expand Down Expand Up @@ -170,53 +195,23 @@ function DescribedMixin (base) {
}

createRecursor () {
let recursedProperty = false
let recursedList = false
let recursedIterable = false

let recursor = null
return () => {
let retval = null
do {
if (recursor !== null) {
retval = recursor.next()
if (retval === null) {
recursor = null
}
}

while (recursor === null && (!recursedList || !recursedProperty || !recursedIterable)) {
// Prioritize recursing lists
if (!recursedList) {
const replay = recursorUtils.replay(this.listState, () => this.createListRecursor())
this.listState = replay.state
recursor = replay.recursor
recursedList = true
if (recursor !== recursorUtils.NOOP_RECURSOR) {
retval = stats.describeListRecursor(recursor)
}
} else if (!recursedProperty) {
const replay = recursorUtils.replay(this.propertyState, () => this.createPropertyRecursor())
this.propertyState = replay.state
recursor = replay.recursor
recursedProperty = true
if (recursor !== recursorUtils.NOOP_RECURSOR) {
retval = stats.describePropertyRecursor(recursor)
}
} else if (!recursedIterable) {
const replay = recursorUtils.replay(this.iterableState, () => this.createIterableRecursor())
this.iterableState = replay.state
recursor = replay.recursor
recursedIterable = true
if (recursor !== recursorUtils.NOOP_RECURSOR) {
retval = stats.describeIterableRecursor(recursor)
}
}
}
} while (recursor !== null && retval === null)
let i = 0
const nextFromObject = () => {
const nextFromRecursor = recursor !== null ? recursor.next() : null
if (nextFromRecursor !== null) return nextFromRecursor
recursor = null

while (i < recursorQueue.length) {
const advanceRecursor = recursorQueue[i++]
const result = advanceRecursor(this)
recursor = result[0]
if (recursor !== null) return result[1]
}

return retval
return null
}
return nextFromObject
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions lib/recursorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ function replay (state, create) {
const next = () => {
if (done) return null

let retval = state.buffer[index]
if (retval === undefined) {
retval = state.buffer[index] = state.next()
}
if (index >= state.buffer.length) state.buffer[index] = state.next()
const retval = state.buffer[index]

index++
if (retval === null) {
Expand Down