Comparing version 0.7.66 to 0.7.67
{ | ||
"name": "squishjs", | ||
"version": "0.7.66", | ||
"version": "0.7.67", | ||
"description": "squish & unsquish stuff", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -94,9 +94,12 @@ const listenable = require("./util/listenable"); | ||
clone() { | ||
throw new Error("Clone not implemented"); | ||
} | ||
free() { | ||
this.node.free(); | ||
} | ||
} | ||
module.exports = {gameNode, BaseNode}; | ||
module.exports = {gameNode, BaseNode}; |
@@ -240,4 +240,6 @@ const ASSET_TYPE = 1; | ||
handleStateChange(node, layerName) { | ||
this.state = this.squish(this.game.getLayers()); | ||
this.broadcast(); | ||
if (this.listeners.size > 0) { | ||
this.state = this.squish(this.game.getLayers()); | ||
this.broadcast(); | ||
} | ||
} | ||
@@ -244,0 +246,0 @@ |
@@ -18,5 +18,11 @@ const listenable = function(obj, onChange) { | ||
return new Proxy(obj, handler); | ||
const revocable = Proxy.revocable(obj, handler); | ||
obj.free = () => { | ||
revocable.revoke(); | ||
} | ||
return revocable.proxy; | ||
}; | ||
module.exports = listenable; |
@@ -7,4 +7,7 @@ const { squish, unsquish } = require('../src/squish'); | ||
const { verifyArrayEquality } = require('./utils'); | ||
const Squisher = require('../src/Squisher'); | ||
const Game = require('../src/Game'); | ||
const assert = require('assert'); | ||
const process = require('process'); | ||
@@ -28,3 +31,3 @@ const hypLength = (x, y) => Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); | ||
} | ||
} else if (key === 'input' || key == 'text') { | ||
} else if (key === 'input' || key == 'text' || key == 'free') { | ||
// TODO: Handle all of this in a more generic way | ||
@@ -359,1 +362,55 @@ } else if (preSquish[key] === undefined || preSquish[key] === null) { | ||
// create one hundred nodes and ensure the memory is freed | ||
test("allocate a bunch of nodes", () => { | ||
const initialMemUsage = process.memoryUsage(); | ||
const nodeCount = Math.pow(10, 2); | ||
const root = new GameNode.Text({ | ||
textInfo: { | ||
text: 'I am root', | ||
x: 4, | ||
y: 20, | ||
size: 5, | ||
align: 'center', | ||
color: COLORS.RED | ||
} | ||
}); | ||
const sizeEstimate = squish(root).length; | ||
const fakeGame = new Game(); | ||
fakeGame.getLayers = () => { | ||
return [ | ||
{ | ||
root | ||
} | ||
] | ||
}; | ||
const squisher = new Squisher({game: fakeGame}); | ||
squisher.addListener(() => { | ||
// necessary to hold the reference to the proxy that we should be revoking when we call delete | ||
}); | ||
for (let i = 0; i < nodeCount; i++) { | ||
const gameNode = new GameNode.Text({ | ||
textInfo: { | ||
text: 'I am going to write a whoooooole lot of text like more than 64 characters which is quite a bit. Not like a tweet long but still long, you know?', | ||
x: 4, | ||
y: 20, | ||
size: 5, | ||
align: 'center', | ||
color: COLORS.RED | ||
} | ||
}); | ||
root.addChild(gameNode); | ||
root.removeChild(gameNode.node.id); | ||
gameNode.free(); | ||
} | ||
const postMemUsage = process.memoryUsage(); | ||
assert(postMemUsage.heapTotal - initialMemUsage.heapTotal <= (.05 * initialMemUsage.heapTotal)); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167617
3224
55