@@ -27,6 +27,13 @@ https://github.com/ArthurClemens/JavaScript-Undo-Manager
2727 // functions
2828 execute ;
2929
30+ /**
31+ * Executes a single command.
32+ * @property {object } command - Command
33+ * @property {function } command.undo - Undo function
34+ * @property {function } command.redo - Redo function
35+ * @property {string } action - "undo" or "redo"
36+ */
3037 execute = function ( command , action ) {
3138 if ( ! command || typeof command [ action ] !== 'function' ) {
3239 return this ;
@@ -40,9 +47,12 @@ https://github.com/ArthurClemens/JavaScript-Undo-Manager
4047 } ;
4148
4249 return {
43- /*
44- Add a command to the queue.
45- */
50+ /**
51+ * Adds a command to the queue.
52+ * @property {object } command - Command
53+ * @property {function } command.undo - Undo function
54+ * @property {function } command.redo - Redo function
55+ */
4656 add : function ( command ) {
4757 if ( isExecuting ) {
4858 return this ;
@@ -66,16 +76,17 @@ https://github.com/ArthurClemens/JavaScript-Undo-Manager
6676 return this ;
6777 } ,
6878
69- /*
70- Pass a function to be called on undo and redo actions.
71- */
79+ /**
80+ * Pass a function to be called on undo and redo actions.
81+ * @property {function } callbackFunc - Callback function
82+ */
7283 setCallback : function ( callbackFunc ) {
7384 callback = callbackFunc ;
7485 } ,
7586
76- /*
77- Perform undo: call the undo function at the current index and decrease the index by 1.
78- */
87+ /**
88+ * Performs undo: call the undo function at the current index and decrease the index by 1.
89+ */
7990 undo : function ( ) {
8091 let command = commands [ index ] ;
8192 if ( ! command ) {
@@ -89,9 +100,9 @@ https://github.com/ArthurClemens/JavaScript-Undo-Manager
89100 return this ;
90101 } ,
91102
92- /*
93- Perform redo: call the redo function at the next index and increase the index by 1.
94- */
103+ /**
104+ * Performs redo: call the redo function at the next index and increase the index by 1.
105+ */
95106 redo : function ( ) {
96107 let command = commands [ index + 1 ] ;
97108 if ( ! command ) {
@@ -105,9 +116,9 @@ https://github.com/ArthurClemens/JavaScript-Undo-Manager
105116 return this ;
106117 } ,
107118
108- /*
109- Clear the memory, losing all stored states. Reset the index.
110- */
119+ /**
120+ * Clears the memory, losing all stored states. Resets the index.
121+ */
111122 clear : function ( ) {
112123 let prev_size = commands . length ;
113124
@@ -119,24 +130,44 @@ https://github.com/ArthurClemens/JavaScript-Undo-Manager
119130 }
120131 } ,
121132
133+ /**
134+ * Tests if any undo actions exist.
135+ * @returns {boolean }
136+ */
122137 hasUndo : function ( ) {
123138 return index !== - 1 ;
124139 } ,
125140
141+ /**
142+ * Tests if any redo actions exist.
143+ * @returns {boolean }
144+ */
126145 hasRedo : function ( ) {
127146 return index < commands . length - 1 ;
128147 } ,
129148
149+ /**
150+ * Returns the list of queued commands.
151+ * @returns {array }
152+ */
130153 getCommands : function ( ) {
131154 return commands ;
132155 } ,
133156
157+ /**
158+ * Returns the index of the actions list.
159+ * @returns {number }
160+ */
134161 getIndex : function ( ) {
135162 return index ;
136163 } ,
137164
138- setLimit : function ( l ) {
139- limit = l ;
165+ /**
166+ * Sets the maximum number of undo steps. Default: 0 (unlimited).
167+ * @property {number } max - Maximum number of undo steps
168+ */
169+ setLimit : function ( max ) {
170+ limit = max ;
140171 } ,
141172 } ;
142173 } ;
0 commit comments