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

What is Framer? Join the Community
Return to index
Saurabh Soni
Posted Jul 26 - Read on Facebook

Q: How to reset a FramerJS prototype programatically (through code)?

I have defined a layer on clicking of which I want the prototype to reset to its initial state. I have tried using location.reload() but that reloads from network. How to reset without reloading the prototype from network?


Eelco Lempsink

There’s no built-in solution for this. It’s possible though, because it’s code ;)

How you want to approach this depends a bit on what you’re building. For instance, if all your state is captured in layer states, you can go back to the default state by calling "layer.states.switch('default')" for each layer. This has the additional benefit that it will nicely animate back to the default state. You will need to take into account that you also have to reset other variables that contain state at that point.

There’s also a less subtle approach: use Utils.reset() to reset everything, and wrap all the code in your project in a function, called ‘run’ for example, and call that again after the reset. This is probably as close as you can get to reloading without actually reloading, but it does not have a nice animation.

Both approaches are demonstrated in this project: Click the blue square to change states (the one of the red square will change randomly), the green square to make the layers go back to the default state, and the red square to do a hard reset.

O'Ryan McEntire

Couldn't you just use:

That would just reload the document from cache. Change it to true or leave it out altogether if you want to reload from the network.

Read the entire post on Facebook