This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Jian Li
Posted Apr 25 - Read on Facebook

I create and delete buttons dynamically, and I try to record how many buttons I deleted. However the number recorded doesn't correct, I confused why the number increases exponentially instead of one by one.


Jian Li

One more question, when I destroy elements of a array, and count how many elements be left with "array.lenght" method, the result is the same as before. So I have to move those non-existent elements away from the array like this:
index = roundGroup.indexOf(this)
Is it normal?

Steve Ruiz

Jian - yes, arrays and variables that store a layer will still store that layer, even if it has been destroyed, until they are reinitialized as something else. So to *really* kill a layer, destroy() it and then set its variable name to undefined (e.g. layerA.destroy(); layerA = undefined).

My advice for arrays: use the lodash method _.pull to remove layers from an array. For example, to remove a layer named 'layerA' from an array named 'myArray', use the code _.pull(myArray, layerA).

If I'm storing layers in an array, I'll usually write a function that will do both, pulling a layer from the array and then immediately destroying it.

Read the entire post on Facebook