在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ottypes/json0开源软件地址:https://github.com/ottypes/json0开源编程语言:CoffeeScript 58.7%开源软件介绍:JSON0 OT TypeThe JSON OT type can be used to edit arbitrary JSON documents. FeaturesThe JSON OT type supports the following operations:
JSON0 is an invertable type - which is to say, all operations have an inverse operation which will undo the original op. As such, all operations which delete content have the content to be deleted inline in the operation. But its not perfect - here's a list of things it cannot do:
It also has O(a * b) complexity when transforming large operations by one another (as opposed to O(a + b) which better algorithms can manage). OperationsJSON operations are lists of operation components. The operation is a grouping of these components, applied in order. Each operation component is an object with a
An operation to delete the first array element (
The path ( Summary of operations
Number operationsThe only operation you can perform on a number is to add to it. Remember, you can always replace the number with another number by operating on the number's container.
AddUsage:
Adds X to the number at PATH. If you want to subtract, add a negative number. Lists and ObjectsLists and objects have the same set of operations (Insert, Delete, Replace, Move) but their semantics are very different. List operations shuffle adjacent list items left or right to make space (or to remove space). Object operations do not. You should pick the data structure which will give you the behaviour you want when you design your data model. To make it clear what the semantics of operations will be, list operations and
object operations are named differently. ( Inserting, Deleting and Replacing in a listUsage:
Inserts, deletes, or replaces the element at The last element in the path specifies an index in the list where elements will be deleted, inserted or replaced. The index must be valid (0 <= new index <= list length). The indexes of existing list elements may change when new list elements are added or removed. The replace operation:
is equivalent to a delete followed by an insert:
Given the following list:
applying the following operation:
would result in the following new list:
Moving list elementsYou can move list items by deleting them and & inserting them back elsewhere, but if you do that concurrent operations on the deleted element will be lost. To fix this, the JSON OT type has a special list move operation. Usage:
Moves the list element specified by The new index must be 0 <= index < list length. The new index will be interpreted after the element has been removed from its current position. Given the following data:
the following operation:
will result in the following data:
Inserting, Deleting and Replacing in an objectUsage:
Set the element indicated by When inserting, the key must not already be used. When deleting or replacing a
value, As with lists, the replace operation:
is equivalent to a delete followed by an insert:
There is (unfortunately) no equivalent for list move with objects. Subtype operationsUsage:
To register a subtype, call
See the OT types documentation for details on these methods. Text subtypeThe old string operations are still supported (see below) but are now implemented internally as a subtype
using the To edit a string, create a
If you wanted to delete the
Note the path. The components, in order, are the key to the list, and the index to
the Insert into a stringUsage:
Insert Delete from a stringUsage:
Delete String operationsThese operations are now internally implemented as subtype operations using the If the content at a path is a string, an operation can edit the string in-place, either deleting characters or inserting characters. To edit a string, add the string offset to the path. For example, given the following object:
If you wanted to delete the
Note the path. The components, in order, are the key to the list, the index to
the Insert into a stringUsage:
Insert Delete from a stringUsage:
Delete CommentaryThis library was written a couple of years ago by Jeremy Apthorp. It was originally written in coffeescript as part of ShareJS, and then it got pulled out into the share/ottypes library and its finally landed here. The type uses the list-of-op-components model, where each operation makes a series of individual changes to a document. Joseph now thinks this is a terrible idea because it doesn't scale well to large operations - it has N2 instead of 2N complexity. Jeremy and Joseph have talked about rewriting this library to instead make each operation be a sparse traversal of the document. But it was obnoxiously difficult to implement JSON OT correctly in the first place - it'll probably take both of us thinking about nothing else for a few weeks to make that happen. When it was written, the embedded text0 type was sharejs's text type. Its since been rewritten to make each operation be a traversal, but the JSON OT type still embeds the old type. As such, that old text type is included in this repository. If you want to use text0 in your own project, I'd be very happy to pull it out of here and make it its own module. However, I recommend that you just use the new text type. Its simpler and faster. LicenseAll code contributed to this repository is licensed under the standard MIT license: Copyright 2011 ottypes library contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following condition: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论