| 224 | * Handles changes, if they exist, by pushing to the undo stack. |
| 225 | */ |
| 226 | function handleChange(currentState, newState) { |
| 227 | if (currentState.equals(newState)) { |
| 228 | return newState; |
| 229 | } |
| 230 | let result = newState.set( |
| 231 | 'undoStack', |
| 232 | newState.get('undoStack').push(currentState.remove('undoStack')) |
| 233 | ).deleteIn( |
| 234 | ['metadata', 'gistUrl'] |
| 235 | ).setIn( |
| 236 | ['metadata', 'created'], |
| 237 | new Date() |
| 238 | ); |
| 239 | |
| 240 | // If it's the first change, update the parent link. |
| 241 | if (currentState.get('undoStack').size === 0) { |
| 242 | result = result.setIn(['metadata', 'original'], Immutable.fromJS({ |
| 243 | title: currentState.getIn(['metadata', 'title']), |
| 244 | url: location.href |
| 245 | })); |
| 246 | } |
| 247 | return result; |
| 248 | } |
| 249 | |
| 250 | function undo(state) { |
| 251 | if (state.get('undoStack').size === 0) { |