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

Commit

Permalink
Converged two separate config flags into one. Updated tests according…
Browse files Browse the repository at this point in the history
…ly and made slight changes for clarity.
  • Loading branch information
ZoteTheMighty committed Apr 20, 2018
1 parent f52c617 commit f032e73
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
11 changes: 5 additions & 6 deletions lib/Component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,8 @@ end
function Component:_update(newProps, newState)
self._setStateBlockedReason = "shouldUpdate"

-- TODO: Encapsulate the instrumentation more gracefully
local doUpdate
if GlobalConfig.getValue("shouldUpdateInstrumentation") then
if GlobalConfig.getValue("componentInstrumentation") then
-- Start timing
local time = tick()
doUpdate = self:shouldUpdate(newProps or self.props, newState or self.state)
Expand Down Expand Up @@ -248,9 +247,9 @@ function Component:_forceUpdate(newProps, newState)
end

self._setStateBlockedReason = "render"
-- TODO: Encapsulate the instrumentation more gracefully

local newChildElement
if GlobalConfig.getValue("renderInstrumentation") then
if GlobalConfig.getValue("componentInstrumentation") then
-- Start timing
local time = tick()
newChildElement = self:render()
Expand All @@ -261,6 +260,7 @@ function Component:_forceUpdate(newProps, newState)
else
newChildElement = self:render()
end

self._setStateBlockedReason = nil

self._setStateBlockedReason = "reconcile"
Expand Down Expand Up @@ -295,9 +295,8 @@ function Component:_reify(handle)

self._setStateBlockedReason = "render"

-- TODO: Encapsulate the instrumentation more gracefully
local virtualTree
if GlobalConfig.getValue("renderInstrumentation") then
if GlobalConfig.getValue("componentInstrumentation") then
-- Start timing
local time = tick()
virtualTree = self:render()
Expand Down
4 changes: 1 addition & 3 deletions lib/Config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ local defaultConfig = {
-- Enables storage of `debug.traceback()` values on elements for debugging.
["elementTracing"] = false,
-- Enables instrumentation of shouldUpdate
["shouldUpdateInstrumentation"] = false,
-- Enables instrumentation of rendering
["renderInstrumentation"] = false,
["componentInstrumentation"] = false,
}

-- Build a list of valid configuration values up for debug messages.
Expand Down
21 changes: 11 additions & 10 deletions lib/Instrumentation.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ return function()

it("should count and time renders when enabled", function()
GlobalConfig.set({
["renderInstrumentation"] = true,
["componentInstrumentation"] = true,
})
local triggerUpdate

Expand Down Expand Up @@ -44,11 +44,12 @@ return function()
Instrumentation.clearCollectedStats()
GlobalConfig.reset()
end)
it("should count and time shouldUpdate when enabled", function()

it("should count and time shouldUpdate calls when enabled", function()
GlobalConfig.set({
["shouldUpdateInstrumentation"] = true,
["componentInstrumentation"] = true,
})
local setValue
local triggerUpdate
local willDoUpdate = false

local TestComponent = Component:extend("TestComponent")
Expand All @@ -64,9 +65,9 @@ return function()
end

function TestComponent:didMount()
setValue = function(value)
triggerUpdate = function()
self:setState({
value = value,
value = self.state.value + 1,
})
end
end
Expand All @@ -76,17 +77,17 @@ return function()
local instance = Reconciler.reify(Core.createElement(TestComponent))

local stats = Instrumentation.getCollectedStats()
-- Not yet tracked, because only update processing is on
expect(stats.TestComponent).never.to.be.ok()

willDoUpdate = true
setValue("whatevs")
triggerUpdate()

expect(stats.TestComponent).to.be.ok()
expect(stats.TestComponent.updateReqCount).to.equal(1)
expect(stats.TestComponent.didUpdateCount).to.equal(1)

willDoUpdate = false
setValue("whatevs")
triggerUpdate()

expect(stats.TestComponent.updateReqCount).to.equal(2)
expect(stats.TestComponent.didUpdateCount).to.equal(1)
expect(stats.TestComponent.shouldUpdateTime).never.to.equal(0)
Expand Down

0 comments on commit f032e73

Please sign in to comment.