Skip to content

Commit

Permalink
Rename from MEMOIZE to memo
Browse files Browse the repository at this point in the history
  • Loading branch information
mintexists committed Oct 6, 2022
1 parent c38d039 commit 9e13724
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 86 deletions.
78 changes: 39 additions & 39 deletions build/habitat-embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,40 +701,6 @@ const Habitat = {}

}

//======//
// Main //
//======//
Habitat.install = (global) => {

if (Habitat.installed) return

if (!Habitat.Array.installed) Habitat.Array.install(global)
if (!Habitat.Async.installed) Habitat.Async.install(global)
if (!Habitat.Colour.installed) Habitat.Colour.install(global)
if (!Habitat.Console.installed) Habitat.Console.install(global)
if (!Habitat.Document.installed) Habitat.Document.install(global)
if (!Habitat.Event.installed) Habitat.Event.install(global)
if (!Habitat.HTML.installed) Habitat.HTML.install(global)
if (!Habitat.JS.installed) Habitat.JS.install(global)
if (!Habitat.Keyboard.installed) Habitat.Keyboard.install(global)
if (!Habitat.LinkedList.installed) Habitat.LinkedList.install(global)
if (!Habitat.Math.installed) Habitat.Math.install(global)
if (!Habitat.Mouse.installed) Habitat.Mouse.install(global)
if (!Habitat.Number.installed) Habitat.Number.install(global)
if (!Habitat.Object.installed) Habitat.Object.install(global)
if (!Habitat.Random.installed) Habitat.Random.install(global)
if (!Habitat.Stage.installed) Habitat.Stage.install(global)
if (!Habitat.String.installed) Habitat.String.install(global)
if (!Habitat.Struct.installed) Habitat.Struct.install(global)
if (!Habitat.Touches.installed) Habitat.Touches.install(global)
if (!Habitat.Tween.installed) Habitat.Tween.install(global)
if (!Habitat.Type.installed) Habitat.Type.install(global)
if (!Habitat.MEMOIZE.installed) Habitat.MEMOIZE.install(global)

Habitat.installed = true

}

//======//
// Math //
//======//
Expand Down Expand Up @@ -1528,15 +1494,49 @@ Habitat.install = (global) => {

}

//======//
// Main //
//======//
Habitat.install = (global) => {

if (Habitat.installed) return

if (!Habitat.Array.installed) Habitat.Array.install(global)
if (!Habitat.Async.installed) Habitat.Async.install(global)
if (!Habitat.Colour.installed) Habitat.Colour.install(global)
if (!Habitat.Console.installed) Habitat.Console.install(global)
if (!Habitat.Document.installed) Habitat.Document.install(global)
if (!Habitat.Event.installed) Habitat.Event.install(global)
if (!Habitat.HTML.installed) Habitat.HTML.install(global)
if (!Habitat.JS.installed) Habitat.JS.install(global)
if (!Habitat.Keyboard.installed) Habitat.Keyboard.install(global)
if (!Habitat.LinkedList.installed) Habitat.LinkedList.install(global)
if (!Habitat.Math.installed) Habitat.Math.install(global)
if (!Habitat.Mouse.installed) Habitat.Mouse.install(global)
if (!Habitat.Number.installed) Habitat.Number.install(global)
if (!Habitat.Object.installed) Habitat.Object.install(global)
if (!Habitat.Random.installed) Habitat.Random.install(global)
if (!Habitat.Stage.installed) Habitat.Stage.install(global)
if (!Habitat.String.installed) Habitat.String.install(global)
if (!Habitat.Struct.installed) Habitat.Struct.install(global)
if (!Habitat.Touches.installed) Habitat.Touches.install(global)
if (!Habitat.Tween.installed) Habitat.Tween.install(global)
if (!Habitat.Type.installed) Habitat.Type.install(global)
if (!Habitat.memo.installed) Habitat.memo.install(global)

Habitat.installed = true

}

//=========//
// Memoize //
//=========//
{
// Memoize the function - Modified from https://tjinlag.medium.com/memoize-javascript-function-638f3b7c80e9
// keymaker is optional and allows you to specifiy a method for generating the key for the cache
// It should be used if the default method is not suitable for the use case
// The MEMOIZE function returns a new function that will now be memoized, meaning it caches results
Habitat.MEMOIZE = (fn, keyMaker) => {
// The memo function returns a new function that will now be memoized, meaning it caches results
Habitat.memo = (fn, keyMaker) => {
// Make a Map (similar to an object but with faster lookup) to store the results of the function
const cache = new Map()

Expand All @@ -1559,9 +1559,9 @@ Habitat.install = (global) => {
}
}

Habitat.MEMOIZE.install = (global) => {
global.MEMOIZE = Habitat.MEMOIZE
Habitat.MEMOIZE.installed = true
Habitat.memo.install = (global) => {
global.memo = Habitat.memo
Habitat.memo.installed = true
}

}
78 changes: 39 additions & 39 deletions build/habitat-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,40 +701,6 @@ const Habitat = {}

}

//======//
// Main //
//======//
Habitat.install = (global) => {

if (Habitat.installed) return

if (!Habitat.Array.installed) Habitat.Array.install(global)
if (!Habitat.Async.installed) Habitat.Async.install(global)
if (!Habitat.Colour.installed) Habitat.Colour.install(global)
if (!Habitat.Console.installed) Habitat.Console.install(global)
if (!Habitat.Document.installed) Habitat.Document.install(global)
if (!Habitat.Event.installed) Habitat.Event.install(global)
if (!Habitat.HTML.installed) Habitat.HTML.install(global)
if (!Habitat.JS.installed) Habitat.JS.install(global)
if (!Habitat.Keyboard.installed) Habitat.Keyboard.install(global)
if (!Habitat.LinkedList.installed) Habitat.LinkedList.install(global)
if (!Habitat.Math.installed) Habitat.Math.install(global)
if (!Habitat.Mouse.installed) Habitat.Mouse.install(global)
if (!Habitat.Number.installed) Habitat.Number.install(global)
if (!Habitat.Object.installed) Habitat.Object.install(global)
if (!Habitat.Random.installed) Habitat.Random.install(global)
if (!Habitat.Stage.installed) Habitat.Stage.install(global)
if (!Habitat.String.installed) Habitat.String.install(global)
if (!Habitat.Struct.installed) Habitat.Struct.install(global)
if (!Habitat.Touches.installed) Habitat.Touches.install(global)
if (!Habitat.Tween.installed) Habitat.Tween.install(global)
if (!Habitat.Type.installed) Habitat.Type.install(global)
if (!Habitat.MEMOIZE.installed) Habitat.MEMOIZE.install(global)

Habitat.installed = true

}

//======//
// Math //
//======//
Expand Down Expand Up @@ -1528,15 +1494,49 @@ Habitat.install = (global) => {

}

//======//
// Main //
//======//
Habitat.install = (global) => {

if (Habitat.installed) return

if (!Habitat.Array.installed) Habitat.Array.install(global)
if (!Habitat.Async.installed) Habitat.Async.install(global)
if (!Habitat.Colour.installed) Habitat.Colour.install(global)
if (!Habitat.Console.installed) Habitat.Console.install(global)
if (!Habitat.Document.installed) Habitat.Document.install(global)
if (!Habitat.Event.installed) Habitat.Event.install(global)
if (!Habitat.HTML.installed) Habitat.HTML.install(global)
if (!Habitat.JS.installed) Habitat.JS.install(global)
if (!Habitat.Keyboard.installed) Habitat.Keyboard.install(global)
if (!Habitat.LinkedList.installed) Habitat.LinkedList.install(global)
if (!Habitat.Math.installed) Habitat.Math.install(global)
if (!Habitat.Mouse.installed) Habitat.Mouse.install(global)
if (!Habitat.Number.installed) Habitat.Number.install(global)
if (!Habitat.Object.installed) Habitat.Object.install(global)
if (!Habitat.Random.installed) Habitat.Random.install(global)
if (!Habitat.Stage.installed) Habitat.Stage.install(global)
if (!Habitat.String.installed) Habitat.String.install(global)
if (!Habitat.Struct.installed) Habitat.Struct.install(global)
if (!Habitat.Touches.installed) Habitat.Touches.install(global)
if (!Habitat.Tween.installed) Habitat.Tween.install(global)
if (!Habitat.Type.installed) Habitat.Type.install(global)
if (!Habitat.memo.installed) Habitat.memo.install(global)

Habitat.installed = true

}

//=========//
// Memoize //
//=========//
{
// Memoize the function - Modified from https://tjinlag.medium.com/memoize-javascript-function-638f3b7c80e9
// keymaker is optional and allows you to specifiy a method for generating the key for the cache
// It should be used if the default method is not suitable for the use case
// The MEMOIZE function returns a new function that will now be memoized, meaning it caches results
Habitat.MEMOIZE = (fn, keyMaker) => {
// The memo function returns a new function that will now be memoized, meaning it caches results
Habitat.memo = (fn, keyMaker) => {
// Make a Map (similar to an object but with faster lookup) to store the results of the function
const cache = new Map()

Expand All @@ -1559,9 +1559,9 @@ Habitat.install = (global) => {
}
}

Habitat.MEMOIZE.install = (global) => {
global.MEMOIZE = Habitat.MEMOIZE
Habitat.MEMOIZE.installed = true
Habitat.memo.install = (global) => {
global.memo = Habitat.memo
Habitat.memo.installed = true
}

}
Expand Down
2 changes: 1 addition & 1 deletion examples/example-embed-multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<script src="../source/javascript.js"></script>
<script src="../source/keyboard.js"></script>
<script src="../source/linkedList.js"></script>
<script src="../source/main.js"></script>
<script src="../source/math.js"></script>
<script src="../source/mouse.js"></script>
<script src="../source/number.js"></script>
Expand All @@ -23,6 +22,7 @@
<script src="../source/touch.js"></script>
<script src="../source/tween.js"></script>
<script src="../source/type.js"></script>
<script src="../source/main.js"></script>
<script src="../source/memoize.js"></script>
<script>

Expand Down
2 changes: 1 addition & 1 deletion source/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Habitat.install = (global) => {
if (!Habitat.Touches.installed) Habitat.Touches.install(global)
if (!Habitat.Tween.installed) Habitat.Tween.install(global)
if (!Habitat.Type.installed) Habitat.Type.install(global)
if (!Habitat.MEMOIZE.installed) Habitat.MEMOIZE.install(global)
if (!Habitat.memo.installed) Habitat.memo.install(global)

Habitat.installed = true

Expand Down
10 changes: 5 additions & 5 deletions source/memoize.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Memoize the function - Modified from https://tjinlag.medium.com/memoize-javascript-function-638f3b7c80e9
// keymaker is optional and allows you to specifiy a method for generating the key for the cache
// It should be used if the default method is not suitable for the use case
// The MEMOIZE function returns a new function that will now be memoized, meaning it caches results
Habitat.MEMOIZE = (fn, keyMaker) => {
// The memo function returns a new function that will now be memoized, meaning it caches results
Habitat.memo = (fn, keyMaker) => {
// Make a Map (similar to an object but with faster lookup) to store the results of the function
const cache = new Map()

Expand All @@ -29,9 +29,9 @@
}
}

Habitat.MEMOIZE.install = (global) => {
global.MEMOIZE = Habitat.MEMOIZE
Habitat.MEMOIZE.installed = true
Habitat.memo.install = (global) => {
global.memo = Habitat.memo
Habitat.memo.installed = true
}

}
2 changes: 1 addition & 1 deletion tinker/tinker.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<script src="../source/javascript.js"></script>
<script src="../source/keyboard.js"></script>
<script src="../source/linkedList.js"></script>
<script src="../source/main.js"></script>
<script src="../source/math.js"></script>
<script src="../source/mouse.js"></script>
<script src="../source/number.js"></script>
Expand All @@ -24,5 +23,6 @@
<script src="../source/touch.js"></script>
<script src="../source/tween.js"></script>
<script src="../source/type.js"></script>
<script src="../source/main.js"></script>
<script src="../source/memoize.js"></script>
<body><script src="tinker.js"></script></body>

0 comments on commit 9e13724

Please sign in to comment.