Skip to content

Commit

Permalink
Stop using Map in JSTimers
Browse files Browse the repository at this point in the history
Reviewed By: fromcelticpark

Differential Revision: D5292912

fbshipit-source-id: a14552b895d586cf24627cc457069d9909b2ecc2
  • Loading branch information
javache authored and facebook-github-bot committed Jun 22, 2017
1 parent 94d9f00 commit e9f657f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions Libraries/Core/Timers/JSTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ const JSTimers = {
const id = _allocateCallback(
timeout != null ?
deadline => {
const timeoutId = JSTimersExecution.requestIdleCallbackTimeouts.get(id);
const timeoutId = JSTimersExecution.requestIdleCallbackTimeouts[id];
if (timeoutId) {
JSTimers.clearTimeout(timeoutId);
JSTimersExecution.requestIdleCallbackTimeouts.delete(id);
JSTimersExecution.requestIdleCallbackTimeouts[id];

This comment has been minimized.

Copy link
@fabriziomoscon

fabriziomoscon Sep 8, 2017

@javache If you want a 1 to 1 mapping from the old file this should have been changed to delete ... [id]

}
return func(deadline);
} :
Expand All @@ -164,12 +164,12 @@ const JSTimers = {
JSTimersExecution.requestIdleCallbacks.splice(index, 1);
JSTimersExecution.callTimer(id, performanceNow(), true);
}
JSTimersExecution.requestIdleCallbackTimeouts.delete(id);
delete JSTimersExecution.requestIdleCallbackTimeouts[id];
if (JSTimersExecution.requestIdleCallbacks.length === 0) {
Timing.setSendIdleEvents(false);
}
}, timeout);
JSTimersExecution.requestIdleCallbackTimeouts.set(id, timeoutId);
JSTimersExecution.requestIdleCallbackTimeouts[id] = timeoutId;
}
return id;
},
Expand All @@ -181,10 +181,10 @@ const JSTimers = {
JSTimersExecution.requestIdleCallbacks.splice(index, 1);
}

const timeoutId = JSTimersExecution.requestIdleCallbackTimeouts.get(timerID);
const timeoutId = JSTimersExecution.requestIdleCallbackTimeouts[timerID];
if (timeoutId) {
JSTimers.clearTimeout(timeoutId);
JSTimersExecution.requestIdleCallbackTimeouts.delete(timerID);
delete JSTimersExecution.requestIdleCallbackTimeouts[timerID];
}

if (JSTimersExecution.requestIdleCallbacks.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Core/Timers/JSTimersExecution.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const JSTimersExecution = {
timerIDs: ([] : Array<?number>),
immediates: [],
requestIdleCallbacks: [],
requestIdleCallbackTimeouts: (new Map() : Map<number, number>),
requestIdleCallbackTimeouts: ({} : {[number]: number}),
identifiers: ([] : Array<null | {methodName: string}>),

errors: (null : ?Array<Error>),
Expand Down

1 comment on commit e9f657f

@esprehn
Copy link
Contributor

@esprehn esprehn commented on e9f657f Aug 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a backstory for this change? Very curious why the Map wasn't working out. :)

Please sign in to comment.