MCPcopy
hub / github.com/viliusle/miniPaint / free

Method free

src/js/core/base-state.js:155–198  ·  view source on GitHub ↗
(memory_size = 0, database_size = 0)

Source from the content-addressed store, hash-verified

153
154 // Frees history actions up to the specified memory & database size. Starts with undo history, then moves to redo history.
155 async free(memory_size = 0, database_size = 0) {
156 let total_memory_freed = 0;
157 let total_database_freed = 0;
158 let has_error = false;
159 let free_complete = false;
160 while (this.action_history_index > 0) {
161 let action = this.action_history.shift();
162 total_memory_freed += action.memory_estimate;
163 total_database_freed += action.database_estimate;
164 try {
165 await action.free();
166 } catch (error) {
167 has_error = true;
168 }
169 if (total_memory_freed >= memory_size && total_database_freed >= database_size) {
170 free_complete = true;
171 break;
172 }
173 this.action_history_index--;
174 }
175 if (!free_complete) {
176 for (let i = this.action_history.length - 1; i >= 0; i--) {
177 let action = this.action_history[i];
178 total_memory_freed += action.memory_estimate;
179 total_database_freed += action.database_estimate;
180 try {
181 await action.free();
182 } catch (error) {
183 has_error = true;
184 }
185 if (total_memory_freed >= memory_size && total_database_freed >= database_size) {
186 free_complete = true;
187 break;
188 }
189 }
190 }
191 if (has_error) {
192 alertify.error('A problem occurred while removing undo history. It\'s suggested you save your work and refresh the page in order to free up memory.');
193 }
194 return {
195 total_memory_freed,
196 total_database_freed
197 }
198 }
199
200 save() {
201 const message = 'window.State.save() is removed. Use State.do_action() to manage undo history instead.';

Callers 1

do_actionMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected