A mapping of the events this array could emit to each event's unique name. Use this to refer an event name, e.g.
rtStr.on(RealTimeString.Events.INSERT, function listener(e) {
// ...
})
Adds a new event listener for the specified event. The class will ignore duplicate registrations of the same listener to the same event.
The name of the event to add the listener for.
The listener callback to register.
This object, in support of a fluent API.
Provides the events emitted by this object as an Observable stream.
An Observable stream of all events emitted by this object.
Each node within a RealTimeModel has a system-generated ID that is unique within this model's contents.
a unique (to the model) ID for this element
Creates an IndexReference anchored to this string. Its index is automatically updated on all local and remote changes.
See the developer guide for more information.
a unique name for the reference
A local index reference anchored to this string
Inserts a substring of zero or more characters into this string at the provided index. Subsequent characters are shifted to the right appropriately.
rtString.value() // "Hello world"
rtString.insert(6, 'magical ');
rtString.value() // "Hello magical world"
On a successful insert
, a StringInsertEvent will be emitted to any remote users.
the zero-based index at which to being inserting the new value
the single character or substring to be inserted
True if the element is currently set up to synchronize with the server.
True if the element is no longer synchronizing with the server. See the developer guide for more information.
Just like the string.length
Javascript property. Returns the number of characters
in this string.
rtString.value() // "Hello world"
rtString.length() // 11
Returns the model to which this element belongs.
Removes a single event listener for a specific event.
The name of the event to remove the listener for.
The listener callback to unregister.
This object, in support of a fluent API.
Adds a new event listener for the specified event. The class will ignore duplicate registrations of the same listener to the same event.
The name of the event to add the listener for.
The listener callback to register.
This object, in support of a fluent API.
Adds a single shot event listener for the specified event. The listener will be called the first time the specified event is fired after the event registration occurs, after which the registration will be removed and no further events will be passed to the listener.
The name of the event to add the listener for.
The listener callback to register.
This object, in support of a fluent API.
Returns the parent of this element within the model.
the parent of this element, or this
if this is the root element
The Path representing this element's location in the containing model's data. For instance, with model data
{
user: {
age: 32
}
}
The RealTimeNumber representing 32
would have path ['user', 'age']
.
Creates a LocalRangeReference bound to this object. Its index bounds are automatically updated on all local and remote changes.
See the developer guide for more information.
a unique name for the range reference
A local range reference anchored to this string
Returns the remote ModelReference created by the given sessionId
with
the unique name key
, or undefined
if no such reference exists.
See Remote References in the developer guide.
The session ID that created the reference
the reference's unique key
Returns any remote references that match the given filter. You can provide
a single key
which could return references from multiple users, sessionId
which would return all of a particular user session's references, or both,
which is really just the same as using the reference method.
an object containing either a sessionId
, key
, or both
An array of remote ModelReferences, or an empty array if there were no matches.
This returns the PathElement representing this element's location relevant to its parent. For example, given a model with contents
{
obj: {
with: 1,
stuff: ['a', 'string']
}
}
let rtNumber = rtModel.elementAt(['obj', 'with']);
rtNumber.value() // 1
rtNumber.relativePath() // 'with'
let rtString = rtModel.elementAt(['obj', 'stuff', 0]);
rtString.value() // 'a'
rtString.relativePath() // 0
a PathElement representing this node's location relative to its parent, or null if it has no parent.
Removes length
characters from this string, starting at index
. Subsequent
characters are left-shifted appropriately.
On a successful remove
, a StringRemoveEvent will be emitted to any remote users.
rtString.value() // "Hello world"
rtString.remove(0, 6);
rtString.value() // "world"
the zero-based index at which to start removing characters
the number of characters to remove
Removes all listeners for all events. This is useful for cleanup before disposing of this particular event emitter.
This object, in support of a fluent API.
A convenience function to delete this element. Throws an error if this is the root object in a model.
Removes a single event listener for a specific event.
The name of the event to remove the listener for.
The listener callback to unregister.
This object, in support of a fluent API.
Removes all listeners bound on the given event.
the name of the event to remove listeners for
This object, in support of a fluent API.
Replaces a portion of the string with a new value at index
. The splice
method will remove deleteCount
characters at index
(inclusive) and then
insert insertValue
at index
.Subsequent characters are shifted left or right
based on if more characters are inserted or removed.
Note that it is possible to perform a remove, without inserting a new value.
Likewise, it is possible to insert a new string without removing any
existing characters. In this way, splice can be used to model both an
insert and a remove. The insert
and remove
methods are provide a
simplifications.
On a successful splice
, one of three events will be emitted base on how
the method was called (and the effect change that will be made to the string
after any remote conflicts are resolved) as follows:
deleteCount
equals 0 and insertValue
is a non-empty string.deleteCount
is greater than zero and insertValue
is an
empty string.deleteCount
is greater than zero and insertValue
is non-
empty string.the zero-based index at which to start removing characters
the number of characters to remove in the current string.
The value to insert at the index.
Returns a JSON-compatible representation of this element.
This element's type. See [[ModelElementType]] for an enumeration of types.
Returns the current underlying value of this element. Note that the return value will not be kept up to date automatically; rather, this function will need to be called each time the most up-to-date value is required.
Sets the value of this element, whose type must be the underlying type of this object.
On a successful value
call, the appropriate IValueChangedEvent will be emitted
to any remote users. This will be one of:
the new value for this object.
This is a distributed string that wraps a native javascript
string
. Most often, these objects are mutated with the insert and remove methods which can operate on either individual characters or substrings.See RealTimeStringEvents for the events that can be emitted on remote changes to this object.
Convergence supports two types of references unique to RealTimeStrings. These are useful for rendering remote cursors and selections.
See the developer guide for the most common use cases.