# Class: Operation

Defined in: | lib/Types/BasicTypes.coffee

## Overview

A generic interface to operations.

An operation has the following methods: _encode: encodes an operation (needed only if instance of this operation is sent). execute: execute the effects of this operations. Good examples are Insert-type and AddName-type val: in the case that the operation holds a value

Furthermore an encodable operation has a parser.

## Direct Known Subclasses

Delete Insert Delimiter

## Instance Method Summary

- # (void) on(event, f) Add an event listener.
- # (void) callEvent(event, args) Fire an event.
- # (void) setParent(o) Set the parent of this operation.
- # (void) getUid() Computes a unique identifier (uid) that identifies this operation.
- # (void) execute() Private Notify the all the listeners.
- ~ (void) saveOperation(name, op_uid) Private Operations may depend on other operations (linked lists, etc.).
- # (Boolean) validateSavedOperations() Private After calling this function all not instantiated operations will be accessible.

## Constructor Details

# (void) constructor(uid)

### Parameters:

- uid ( `Object` ) — A unique identifier. If uid is undefined, a new uid will be created.

### See also:

- HistoryBuffer.getNextOperationIdentifier

## Instance Method Details

# (void) on(event, f)

Add an event listener. It depends on the operation which events are supported.

### Parameters:

- event ( `String` ) — Name of the event.
- f ( `Function` ) — f is executed in case the event fires.

# (void) callEvent(event, args)

Fire an event. TODO: Do something with timeouts. You don't want this to fire for every operation (e.g. insert).

# (void) setParent(o)

Set the parent of this operation.

# (void) getUid()

Computes a unique identifier (uid) that identifies this operation.

# (void) execute() Private

Notify the all the listeners.

~ (void) saveOperation(name, op_uid)
~ (void) saveOperation(name, op)

Operations may depend on other operations (linked lists, etc.). The saveOperation and validateSavedOperations methods provide an easy way to refer to these operations via an uid or object reference.

For example: We can create a new Delete operation that deletes the operation $o like this

    - var d = new Delete(uid, $o);   or
    - var d = new Delete(uid, $o.getUid());

Either way we want to access $o via d.deletes. In the second case validateSavedOperations must be called first.

### Overloads:

~ (void) saveOperation(name, op_uid)

### Parameters:

- name ( `String` ) — The name of the operation. After validating (with validateSavedOperations) the instantiated operation will be accessible via this[name].
- op_uid ( `Object` ) — A uid that refers to an operation

~ (void) saveOperation(name, op)

### Parameters:

- name ( `String` ) — The name of the operation. After calling this function op is accessible via this[name].
- op ( `Operation` ) — An Operation object

# (Boolean) validateSavedOperations() Private

After calling this function all not instantiated operations will be accessible.

### Returns:

- ( `Boolean` ) — Whether it was possible to instantiate all operations.

### See also:

- Operation.saveOperation

Quickly fuzzy find classes, mixins, methods, file:

- T Open fuzzy finder dialog

Control the navigation frame:

- L Toggle list view
- C Show class list
- I Show mixin list
- F Show file list
- M Show method list
- E Show extras list

You can focus and blur the search input:

- S Focus search input
- Esc Blur search input