Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
12 additions
and
0 deletions.
-
+12
−0
framer/Utils.coffee
|
@@ -120,6 +120,18 @@ Utils.throttle = (delay, fn) -> |
|
|
setTimeout (-> timer = false), delay unless delay is -1 |
|
|
fn arguments... |
|
|
|
|
|
# Taken from http://addyosmani.com/blog/faster-javascript-memoization/ |
|
|
Utils.memoize = (fn) -> -> |
|
|
args = Array::slice.call(arguments) |
|
|
hash = "" |
|
|
i = args.length |
|
|
currentArg = null |
|
|
while i-- |
|
|
currentArg = args[i] |
|
|
hash += (if (currentArg is Object(currentArg)) then JSON.stringify(currentArg) else currentArg) |
|
|
fn.memoize or (fn.memoize = {}) |
|
|
(if (hash of fn.memoize) then fn.memoize[hash] else fn.memoize[hash] = fn.apply(this, args)) |
|
|
|
|
|
|
|
|
###################################################### |
|
|
# HANDY FUNCTIONS |
|
|
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.