update examples
This commit is contained in:
		
							parent
							
								
									4726c71dd0
								
							
						
					
					
						commit
						0b14e90585
					
				@ -43,9 +43,7 @@ Y({
 | 
			
		||||
  // call drawLine every time an array is appended
 | 
			
		||||
  y.share.drawing.observe(function (event) {
 | 
			
		||||
    if (event.type === 'insert') {
 | 
			
		||||
      event.values().then(function (values) {
 | 
			
		||||
        values.forEach(drawLine)
 | 
			
		||||
      })
 | 
			
		||||
      event.values.forEach(drawLine)
 | 
			
		||||
    } else {
 | 
			
		||||
      // just remove all elements (thats what we do anyway)
 | 
			
		||||
      svg.selectAll('path').remove()
 | 
			
		||||
@ -53,7 +51,7 @@ Y({
 | 
			
		||||
  })
 | 
			
		||||
  // draw all existing content
 | 
			
		||||
  for (var i = 0; i < drawing.length; i++) {
 | 
			
		||||
    drawing.get(i).then(drawLine)
 | 
			
		||||
    drawLine(drawing.get(i))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // clear canvas on request
 | 
			
		||||
@ -64,9 +62,7 @@ Y({
 | 
			
		||||
  var sharedLine = null
 | 
			
		||||
  function dragstart () {
 | 
			
		||||
    drawing.insert(drawing.length, [Y.Array])
 | 
			
		||||
    drawing.get(drawing.length - 1).then(function (array) {
 | 
			
		||||
      sharedLine = array
 | 
			
		||||
    })
 | 
			
		||||
    sharedLine = drawing.get(drawing.length - 1)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // After one dragged event is recognized, we ignore them for 33ms.
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,9 @@
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html>
 | 
			
		||||
<head>
 | 
			
		||||
  <!-- 1.0.0-rc.0 does currently not include dist files! We are using the hosted version instead -->
 | 
			
		||||
  <!-- quill does not include dist files! We are using the hosted version instead -->
 | 
			
		||||
  <!--link rel="stylesheet" href="../bower_components/quill/dist/quill.snow.css" /-->
 | 
			
		||||
  <link href="//cdn.quilljs.com/1.0.0-rc.2/quill.snow.css" rel="stylesheet">
 | 
			
		||||
  <link href="https://cdn.quilljs.com/1.0.4/quill.snow.css" rel="stylesheet">
 | 
			
		||||
  <link href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.css" rel="stylesheet"> 
 | 
			
		||||
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/styles/monokai-sublime.min.css" rel="stylesheet">
 | 
			
		||||
  <style>
 | 
			
		||||
@ -21,8 +21,8 @@
 | 
			
		||||
 | 
			
		||||
  <script src="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.5.1/katex.min.js" type="text/javascript"></script>
 | 
			
		||||
  <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.2.0/highlight.min.js" type="text/javascript"></script>
 | 
			
		||||
  <script src="//cdn.quilljs.com/1.0.0-rc.2/quill.js"></script>
 | 
			
		||||
  <!-- 1.0.0-rc.0 does currently not include dist files! We are using the hosted version instead (see above)
 | 
			
		||||
  <script src="https://cdn.quilljs.com/1.0.4/quill.js"></script>
 | 
			
		||||
  <!-- quill does not include dist files! We are using the hosted version instead (see above)
 | 
			
		||||
  <script src="../bower_components/quill/dist/quill.js"></script>
 | 
			
		||||
  -->
 | 
			
		||||
  <script src="../bower_components/yjs/y.es6"></script>
 | 
			
		||||
 | 
			
		||||
@ -7,8 +7,8 @@ Y({
 | 
			
		||||
    name: 'memory'
 | 
			
		||||
  },
 | 
			
		||||
  connector: {
 | 
			
		||||
    name: 'webrtc',
 | 
			
		||||
    room: 'richtext-example-quill-beta'
 | 
			
		||||
    name: 'websockets-client',
 | 
			
		||||
    room: 'richtext-example-quill-1.0'
 | 
			
		||||
  },
 | 
			
		||||
  sourceDir: '/bower_components',
 | 
			
		||||
  share: {
 | 
			
		||||
 | 
			
		||||
@ -16,8 +16,6 @@ Y({
 | 
			
		||||
}).then(function (y) {
 | 
			
		||||
  window.yXml = y
 | 
			
		||||
  // bind xml type to a dom, and put it in body
 | 
			
		||||
  y.share.xml.getDom().then(function (dom) {
 | 
			
		||||
    window.sharedDom = dom
 | 
			
		||||
    document.body.appendChild(dom)
 | 
			
		||||
  })
 | 
			
		||||
  window.sharedDom = y.share.xml.getDom()
 | 
			
		||||
  document.body.appendChild(window.sharedDom)
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										161
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										161
									
								
								README.md
									
									
									
									
									
								
							@ -1,39 +1,28 @@
 | 
			
		||||
 | 
			
		||||
# 
 | 
			
		||||
 | 
			
		||||
Yjs is a framework for optimistic concurrency control and automatic conflict resolution on shared data.
 | 
			
		||||
The framework provides similar functionality as [ShareJs] and [OpenCoweb], but supports peer-to-peer
 | 
			
		||||
communication protocols by default. Yjs was designed to handle concurrent actions on arbitrary data
 | 
			
		||||
like Text, Json, and XML. We also provide support for storing and manipulating your shared data offline.
 | 
			
		||||
For more information and demo applications visit our [homepage](http://y-js.org/).
 | 
			
		||||
Yjs is a framework for p2p shared editing on structured data like (rich-)text, json, and XML.
 | 
			
		||||
It is similar to [ShareJs] and [OpenCoweb], but easy to use.
 | 
			
		||||
For additional information, demos, and tutorials visit [y-js.org](http://y-js.org/).
 | 
			
		||||
 | 
			
		||||
You can create you own shared types easily.
 | 
			
		||||
Therefore, you can design the structure of your custom type,
 | 
			
		||||
and ensure data validity, while Yjs ensures data consistency (everyone will eventually end up with the same data).
 | 
			
		||||
We already provide abstract data types for
 | 
			
		||||
### Extensions
 | 
			
		||||
Yjs only knows how to resolve conflicts on shared data. You have to choose a ..
 | 
			
		||||
* *Connector* - a communication protocol that propagates changes to the clients 
 | 
			
		||||
* *Database* - a database to store your changes
 | 
			
		||||
* one or more *Types* - that represent the shared data
 | 
			
		||||
 | 
			
		||||
| Name     | Description       |
 | 
			
		||||
|----------|-------------------|
 | 
			
		||||
|[map](https://github.com/y-js/y-map) | A shared Map implementation. Maps from text to any stringify-able object |
 | 
			
		||||
|[array](https://github.com/y-js/y-array) | A shared Array implementation |
 | 
			
		||||
|[xml](https://github.com/y-js/y-xml) | An implementation of the DOM. You can create a two way binding to Browser DOM objects |
 | 
			
		||||
|[text](https://github.com/y-js/y-text) | Collaborate on text. Supports two way binding to textareas, input elements, or HTML elements (e.g. <*h1*>, or <*p*>). Also supports the [Ace Editor](https://ace.c9.io) |
 | 
			
		||||
|[richtext](https://github.com/y-js/y-richtext) | Collaborate on rich text. Supports two way binding to the [Quill Rich Text Editor](http://quilljs.com/)|
 | 
			
		||||
Connectors, Databases, and Types are available as modules that extend Yjs. Here is a list of the modules we know of:
 | 
			
		||||
 | 
			
		||||
Yjs supports P2P message propagation, and is not bound to a specific communication protocol. Therefore, Yjs is extremely scalable and can be used in a wide range of application scenarios.
 | 
			
		||||
 | 
			
		||||
We support several communication protocols as so called *Connectors*.
 | 
			
		||||
You can create your own connector too - read [this wiki page](https://github.com/y-js/yjs/wiki/Custom-Connectors).
 | 
			
		||||
Currently, we support the following communication protocols:
 | 
			
		||||
##### Connectors
 | 
			
		||||
 | 
			
		||||
|Name            | Description               |
 | 
			
		||||
|----------------|-----------------------------------|
 | 
			
		||||
|[xmpp](https://github.com/y-js/y-xmpp) | Propagate updates in a XMPP multi-user-chat room ([XEP-0045](http://xmpp.org/extensions/xep-0045.html))|
 | 
			
		||||
|[webrtc](https://github.com/y-js/y-webrtc) | Propagate updates Browser2Browser via WebRTC|
 | 
			
		||||
|[websockets](https://github.com/y-js/y-websockets-client) | Exchange updates efficiently in the classical client-server model |
 | 
			
		||||
|[websockets](https://github.com/y-js/y-websockets-client) | Set up [a central server](https://github.com/y-js/y-websockets-client), and connect to it via websockets |
 | 
			
		||||
|[xmpp](https://github.com/y-js/y-xmpp) | Propagate updates in a XMPP multi-user-chat room ([XEP-0045](http://xmpp.org/extensions/xep-0045.html))|
 | 
			
		||||
|[test](https://github.com/y-js/y-test) | A Connector for testing purposes. It is designed to simulate delays that happen in worst case scenarios|
 | 
			
		||||
 | 
			
		||||
You are not limited to use a specific database to store the shared data. We provide the following database adapters:
 | 
			
		||||
##### Database adapters
 | 
			
		||||
 | 
			
		||||
|Name            | Description               |
 | 
			
		||||
|----------------|-----------------------------------|
 | 
			
		||||
@ -41,11 +30,16 @@ You are not limited to use a specific database to store the shared data. We prov
 | 
			
		||||
|[indexeddb](https://github.com/y-js/y-indexeddb) | Offline storage for the browser |
 | 
			
		||||
|[leveldb](https://github.com/y-js/y-leveldb) | Persistent storage for node apps |
 | 
			
		||||
 | 
			
		||||
The advantages over similar frameworks are support for
 | 
			
		||||
* .. P2P message propagation and arbitrary communication protocols
 | 
			
		||||
* .. share any type of data. The types provide a convenient interface
 | 
			
		||||
* .. offline support: Changes are stored persistently and only relevant changes are propagated on rejoin
 | 
			
		||||
* .. Intention Preservation: When working on Text, the intention of your changes are preserved. This is particularily important when working offline. Every type has a notion on how we define Intention Preservation on it.
 | 
			
		||||
 | 
			
		||||
##### Types
 | 
			
		||||
 | 
			
		||||
| Name     | Description       |
 | 
			
		||||
|----------|-------------------|
 | 
			
		||||
|[map](https://github.com/y-js/y-map) | A shared Map implementation. Maps from text to any stringify-able object |
 | 
			
		||||
|[array](https://github.com/y-js/y-array) | A shared Array implementation |
 | 
			
		||||
|[xml](https://github.com/y-js/y-xml) | An implementation of the DOM. You can create a two way binding to Browser DOM objects |
 | 
			
		||||
|[text](https://github.com/y-js/y-text) | Collaborate on text. Supports two way binding to the [Ace Editor](https://ace.c9.io), textareas, input elements, and HTML elements (e.g. <*h1*>, or <*p*>) |
 | 
			
		||||
|[richtext](https://github.com/y-js/y-richtext) | Collaborate on rich text. Supports two way binding to the [Quill Rich Text Editor](http://quilljs.com/)|
 | 
			
		||||
 | 
			
		||||
## Use it! 
 | 
			
		||||
Install Yjs, and its modules with [bower](http://bower.io/), or [npm](https://www.npmjs.org/package/yjs).  
 | 
			
		||||
@ -64,39 +58,67 @@ You only need to include the `y.js` file. Yjs is able to automatically require m
 | 
			
		||||
npm install --save yjs % add all y-* modules you want to use
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
When using npm, you also need to import all modules you want to use.
 | 
			
		||||
If you don't include via script tag, you have to explicitly include all modules! (Same goes for other module systems)
 | 
			
		||||
```
 | 
			
		||||
Y = require('yjs')
 | 
			
		||||
var Y = require('yjs')
 | 
			
		||||
require('y-array')(Y) // add the y-array type to Yjs
 | 
			
		||||
// require('y-websockets-client')(Y) // do the same for all modules you want to use
 | 
			
		||||
require('y-websockets-client')(Y)
 | 
			
		||||
require('y-memory')(Y)
 | 
			
		||||
require('y-array')(Y)
 | 
			
		||||
require('y-map')(Y)
 | 
			
		||||
require('y-text')(Y)
 | 
			
		||||
// ..
 | 
			
		||||
// do the same for all modules you want to use
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
# Text editing example
 | 
			
		||||
Install dependencies
 | 
			
		||||
```
 | 
			
		||||
Y({
 | 
			
		||||
  db: {
 | 
			
		||||
    name: 'memory' // store in memory.
 | 
			
		||||
    // name: 'indexeddb'
 | 
			
		||||
    // name: 'leveldb'
 | 
			
		||||
  },
 | 
			
		||||
  connector: {
 | 
			
		||||
    name: 'websockets-client', // choose the websockets connector
 | 
			
		||||
    // name: 'webrtc'
 | 
			
		||||
    // name: 'xmpp'
 | 
			
		||||
    room: 'Textarea-example-dev'
 | 
			
		||||
  },
 | 
			
		||||
  sourceDir: '/bower_components', // location of the y-* modules (bower only)
 | 
			
		||||
  share: {
 | 
			
		||||
    textarea: 'Text' // y.share.textarea is of type Y.Text
 | 
			
		||||
  }
 | 
			
		||||
  // types: ['Richtext', 'Array'] // optional list of types you want to import (bower only)
 | 
			
		||||
}).then(function (y) {
 | 
			
		||||
  // bind the textarea to a shared text element
 | 
			
		||||
  y.share.textarea.bind(document.getElementById('textfield'))
 | 
			
		||||
}
 | 
			
		||||
bower i yjs y-memory y-webrtc y-array y-text
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
# Api
 | 
			
		||||
Here is a simple example of a shared textarea
 | 
			
		||||
```
 | 
			
		||||
  <!DOCTYPE html>
 | 
			
		||||
  <html>
 | 
			
		||||
    <body>
 | 
			
		||||
      <script src="./bower_components/yjs/y.js"></script>
 | 
			
		||||
      <script>
 | 
			
		||||
        Y({
 | 
			
		||||
          db: {
 | 
			
		||||
            name: 'memory' // use memory database adapter.
 | 
			
		||||
            // name: 'indexeddb'
 | 
			
		||||
            // name: 'leveldb'
 | 
			
		||||
          },
 | 
			
		||||
          connector: {
 | 
			
		||||
            name: 'webrtc', // use webrtc connector
 | 
			
		||||
            // name: 'websockets-client'
 | 
			
		||||
            // name: 'xmpp'
 | 
			
		||||
            room: 'my-room' // clients connecting to the same room share data 
 | 
			
		||||
          },
 | 
			
		||||
          sourceDir: '/bower_components', // location of the y-* modules (browser only)
 | 
			
		||||
          share: {
 | 
			
		||||
            textarea: 'Text' // y.share.textarea is of type y-text
 | 
			
		||||
          }
 | 
			
		||||
        }).then(function (y) {
 | 
			
		||||
          // The Yjs instance `y` is available
 | 
			
		||||
          // y.share.* contains the shared types
 | 
			
		||||
  
 | 
			
		||||
          // Bind the textarea to y.share.textarea
 | 
			
		||||
          y.share.textarea.bind(document.querySelector('textarea'))
 | 
			
		||||
        }
 | 
			
		||||
      </script>
 | 
			
		||||
      <textarea></textarea>
 | 
			
		||||
    </body>
 | 
			
		||||
  </html>
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Get Help & Give Help
 | 
			
		||||
There are some friendly people on [](https://gitter.im/y-js/yjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) who are eager to help, and answer questions. Please join!
 | 
			
		||||
 | 
			
		||||
Report _any_ issues to the [Github issue page](https://github.com/y-js/yjs/issues)! I try to fix them very soon, if possible.
 | 
			
		||||
 | 
			
		||||
# API
 | 
			
		||||
 | 
			
		||||
### Y(options)
 | 
			
		||||
* options.db
 | 
			
		||||
@ -108,14 +130,14 @@ Y({
 | 
			
		||||
  * All of our connectors specify an `url` property that defines the connection endpoint of the used connector.
 | 
			
		||||
    * All of our connectors also have a default connection endpoint that you can use for development. 
 | 
			
		||||
  * Have a look at the used connector repository to see all available options.
 | 
			
		||||
* options.sourceDir
 | 
			
		||||
  * Path where all y-* modules are stored.
 | 
			
		||||
* options.sourceDir (browser only)
 | 
			
		||||
  * Path where all y-* modules are stored
 | 
			
		||||
  * Defaults to `/bower_components`
 | 
			
		||||
  * Not required when running on `nodejs` / `iojs`
 | 
			
		||||
  * When using browserify you can specify all used modules like this:
 | 
			
		||||
  * When using nodejs you need to manually extend Yjs:
 | 
			
		||||
```
 | 
			
		||||
var Y = require('yjs')
 | 
			
		||||
// you need to require the db, connector, and *all* types you use! 
 | 
			
		||||
// you have to require a db, connector, and *all* types you use! 
 | 
			
		||||
require('y-memory')(Y)
 | 
			
		||||
require('y-webrtc')(Y)
 | 
			
		||||
require('y-map')(Y)
 | 
			
		||||
@ -123,13 +145,13 @@ require('y-map')(Y)
 | 
			
		||||
``` 
 | 
			
		||||
* options.share
 | 
			
		||||
  * Specify on `options.share[arbitraryName]` types that are shared among all users.
 | 
			
		||||
  * E.g. Specify `options.share[arbitraryName] = 'Array'` to require y-array and create an Y.Array type on `y.share[arbitraryName]`.
 | 
			
		||||
  * E.g. Specify `options.share[arbitraryName] = 'Array'` to require y-array and create an y-array type on `y.share[arbitraryName]`.
 | 
			
		||||
  * If userA doesn't specify `options.share[arbitraryName]`, it won't be available for userA.
 | 
			
		||||
  * If userB specifies `options.share[arbitraryName]`, it still won't be available for userA. But all the updates are send from userB to userA.
 | 
			
		||||
  * In contrast to Y.Map, types on `y.share.*` cannot be overwritten or deleted. Instead, they are merged among all users. This feature is only available on `y.share.*`
 | 
			
		||||
  * In contrast to y-map, types on `y.share.*` cannot be overwritten or deleted. Instead, they are merged among all users. This feature is only available on `y.share.*`
 | 
			
		||||
  * Weird behavior: It is supported that two users specify different types with the same property name.
 | 
			
		||||
     E.g. userA specifies `options.share.x = 'Array'`, and userB specifies `options.share.x = 'Text'`. But they'll only share data if they specified the same type with the same property name
 | 
			
		||||
* options.type
 | 
			
		||||
     E.g. userA specifies `options.share.x = 'Array'`, and userB specifies `options.share.x = 'Text'`. But they only share data if they specified the same type with the same property name
 | 
			
		||||
* options.type (browser only)
 | 
			
		||||
  * Array of modules that Yjs needs to require, before instantiating a shared type.
 | 
			
		||||
  * By default Yjs requires the specified database adapter, the specified connector, and all modules that are used in `options.share.*`
 | 
			
		||||
  * Put all types here that you intend to use, but are not used in y.share.*
 | 
			
		||||
@ -174,19 +196,14 @@ The promise returns an instance of Y. We denote it with a lower case `y`.
 | 
			
		||||
* y.db.userId :: String
 | 
			
		||||
  * The used user id for this client. **Never overwrite this**
 | 
			
		||||
 | 
			
		||||
## Get help
 | 
			
		||||
There are some friendly people on [](https://gitter.im/y-js/yjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) who may help you with your problem, and answer your questions.
 | 
			
		||||
 | 
			
		||||
Please report _any_ issues to the [Github issue page](https://github.com/y-js/yjs/issues)! I try to fix them very soon, if possible.
 | 
			
		||||
 | 
			
		||||
## Changelog
 | 
			
		||||
 | 
			
		||||
### 12.0.0
 | 
			
		||||
* **Types work are synchronous and never return a promise (except explicitly stated)**
 | 
			
		||||
  * `y.share.map.get('map type') // => returns a Y.Map instead of a promise`
 | 
			
		||||
  * The event property `oldValues` also contains a list of types/values (without wrapper)
 | 
			
		||||
  * Support for the [y-leveldb](https://github.com/y-js/y-leveldb) database adapter
 | 
			
		||||
  * [y-richtext](https://github.com/y-js/y-richtext) supports Quill@1.0.0-rc.2
 | 
			
		||||
* **Types are synchronous and never return a promise (except explicitly stated)**
 | 
			
		||||
  * `y.share.map.get('map type') // => returns a y-map instead of a promise`
 | 
			
		||||
  * The event property `oldValues`, and `values` contain a list of values (without wrapper)
 | 
			
		||||
* Support for the [y-leveldb](https://github.com/y-js/y-leveldb) database adapter
 | 
			
		||||
* [y-richtext](https://github.com/y-js/y-richtext) supports Quill@1.0.0-rc.2
 | 
			
		||||
 | 
			
		||||
### 11.0.0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										24
									
								
								y.es6
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								y.es6
									
									
									
									
									
								
							@ -1097,7 +1097,7 @@ module.exports = function (Y /* :any */) {
 | 
			
		||||
    }
 | 
			
		||||
    /*
 | 
			
		||||
      Init type. This is called when a remote operation is retrieved, and transformed to a type
 | 
			
		||||
      TODO: delete type from store.initializedTypes[id] when corresponding id was deleted! 
 | 
			
		||||
      TODO: delete type from store.initializedTypes[id] when corresponding id was deleted!
 | 
			
		||||
    */
 | 
			
		||||
    * initType (id, args) {
 | 
			
		||||
      var sid = JSON.stringify(id)
 | 
			
		||||
@ -1119,12 +1119,7 @@ module.exports = function (Y /* :any */) {
 | 
			
		||||
      id = id || this.getNextOpId(1)
 | 
			
		||||
      var op = Y.Struct[structname].create(id)
 | 
			
		||||
      op.type = typedefinition[0].name
 | 
			
		||||
      
 | 
			
		||||
      /* TODO: implement for y-xml support
 | 
			
		||||
      if (typedefinition[0].appendAdditionalInfo != null) {
 | 
			
		||||
        yield* typedefinition[0].appendAdditionalInfo.call(this, op, typedefinition[1])
 | 
			
		||||
      }
 | 
			
		||||
      */
 | 
			
		||||
 | 
			
		||||
      this.requestTransaction(function * () {
 | 
			
		||||
        if (op.id[0] === '_') {
 | 
			
		||||
          yield* this.setOperation(op)
 | 
			
		||||
@ -2896,7 +2891,7 @@ module.exports = function (Y /* : any*/) {
 | 
			
		||||
            var _o = yield* transaction.getInsertion(o.id)
 | 
			
		||||
            if (_o.parentSub != null && _o.left != null) {
 | 
			
		||||
              // if o is an insertion of a map struc (parentSub is defined), then it shouldn't be necessary to compute left
 | 
			
		||||
              this.waiting.splice(i,1)
 | 
			
		||||
              this.waiting.splice(i, 1)
 | 
			
		||||
              i-- // update index
 | 
			
		||||
            } else if (!Y.utils.compareIds(_o.id, o.id)) {
 | 
			
		||||
              // o got extended
 | 
			
		||||
@ -3499,6 +3494,9 @@ class YConfig {
 | 
			
		||||
      for (var propertyname in opts.share) {
 | 
			
		||||
        var typeConstructor = opts.share[propertyname].split('(')
 | 
			
		||||
        var typeName = typeConstructor.splice(0, 1)
 | 
			
		||||
        var type = Y[typeName]
 | 
			
		||||
        var typedef = type.typeDefinition
 | 
			
		||||
        var id = ['_', typedef.struct + '_' + typeName + '_' + propertyname + '_' + typeConstructor]
 | 
			
		||||
        var args = []
 | 
			
		||||
        if (typeConstructor.length === 1) {
 | 
			
		||||
          try {
 | 
			
		||||
@ -3506,11 +3504,13 @@ class YConfig {
 | 
			
		||||
          } catch (e) {
 | 
			
		||||
            throw new Error('Was not able to parse type definition! (share.' + propertyname + ')')
 | 
			
		||||
          }
 | 
			
		||||
          if (type.typeDefinition.parseArguments == null) {
 | 
			
		||||
            throw new Error(typeName + ' does not expect arguments!')
 | 
			
		||||
          } else {
 | 
			
		||||
            args = typedef.parseArguments(args[0])[1]
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
        var type = Y[typeName]
 | 
			
		||||
        var typedef = type.typeDefinition
 | 
			
		||||
        var id = ['_', typedef.struct + '_' + typeName + '_' + propertyname + '_' + typeConstructor]
 | 
			
		||||
        share[propertyname] = this.store.createType(type.apply(typedef, args), id)
 | 
			
		||||
        share[propertyname] = yield* this.store.initType.call(this, id, args)
 | 
			
		||||
      }
 | 
			
		||||
      this.store.whenTransactionsFinished()
 | 
			
		||||
        .then(callback)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										70
									
								
								y.js
									
									
									
									
									
								
							
							
						
						
									
										70
									
								
								y.js
									
									
									
									
									
								
							@ -2607,7 +2607,7 @@ module.exports = function (Y /* :any */) {
 | 
			
		||||
      }
 | 
			
		||||
      /*
 | 
			
		||||
        Init type. This is called when a remote operation is retrieved, and transformed to a type
 | 
			
		||||
        TODO: delete type from store.initializedTypes[id] when corresponding id was deleted! 
 | 
			
		||||
        TODO: delete type from store.initializedTypes[id] when corresponding id was deleted!
 | 
			
		||||
      */
 | 
			
		||||
 | 
			
		||||
    }, {
 | 
			
		||||
@ -2665,11 +2665,6 @@ module.exports = function (Y /* :any */) {
 | 
			
		||||
        var op = Y.Struct[structname].create(id);
 | 
			
		||||
        op.type = typedefinition[0].name;
 | 
			
		||||
 | 
			
		||||
        /* TODO: implement for y-xml support
 | 
			
		||||
        if (typedefinition[0].appendAdditionalInfo != null) {
 | 
			
		||||
          yield* typedefinition[0].appendAdditionalInfo.call(this, op, typedefinition[1])
 | 
			
		||||
        }
 | 
			
		||||
        */
 | 
			
		||||
        this.requestTransaction(regeneratorRuntime.mark(function _callee6() {
 | 
			
		||||
          return regeneratorRuntime.wrap(function _callee6$(_context11) {
 | 
			
		||||
            while (1) {
 | 
			
		||||
@ -7078,7 +7073,7 @@ var YConfig = function () {
 | 
			
		||||
      var share = {};
 | 
			
		||||
      this.share = share;
 | 
			
		||||
      this.db.requestTransaction(regeneratorRuntime.mark(function requestTransaction() {
 | 
			
		||||
        var propertyname, typeConstructor, typeName, args, type, typedef, id;
 | 
			
		||||
        var propertyname, typeConstructor, typeName, type, typedef, id, args;
 | 
			
		||||
        return regeneratorRuntime.wrap(function requestTransaction$(_context) {
 | 
			
		||||
          while (1) {
 | 
			
		||||
            switch (_context.prev = _context.next) {
 | 
			
		||||
@ -7087,49 +7082,62 @@ var YConfig = function () {
 | 
			
		||||
 | 
			
		||||
              case 1:
 | 
			
		||||
                if ((_context.t1 = _context.t0()).done) {
 | 
			
		||||
                  _context.next = 20;
 | 
			
		||||
                  _context.next = 26;
 | 
			
		||||
                  break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                propertyname = _context.t1.value;
 | 
			
		||||
                typeConstructor = opts.share[propertyname].split('(');
 | 
			
		||||
                typeName = typeConstructor.splice(0, 1);
 | 
			
		||||
                args = [];
 | 
			
		||||
 | 
			
		||||
                if (!(typeConstructor.length === 1)) {
 | 
			
		||||
                  _context.next = 14;
 | 
			
		||||
                  break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                _context.prev = 7;
 | 
			
		||||
 | 
			
		||||
                args = JSON.parse('[' + typeConstructor[0].split(')')[0] + ']');
 | 
			
		||||
                _context.next = 14;
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
              case 11:
 | 
			
		||||
                _context.prev = 11;
 | 
			
		||||
                _context.t2 = _context['catch'](7);
 | 
			
		||||
                throw new Error('Was not able to parse type definition! (share.' + propertyname + ')');
 | 
			
		||||
 | 
			
		||||
              case 14:
 | 
			
		||||
                type = Y[typeName];
 | 
			
		||||
                typedef = type.typeDefinition;
 | 
			
		||||
                id = ['_', typedef.struct + '_' + typeName + '_' + propertyname + '_' + typeConstructor];
 | 
			
		||||
                args = [];
 | 
			
		||||
 | 
			
		||||
                share[propertyname] = this.store.createType(type.apply(typedef, args), id);
 | 
			
		||||
                if (!(typeConstructor.length === 1)) {
 | 
			
		||||
                  _context.next = 22;
 | 
			
		||||
                  break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                _context.prev = 10;
 | 
			
		||||
 | 
			
		||||
                args = JSON.parse('[' + typeConstructor[0].split(')')[0] + ']');
 | 
			
		||||
                _context.next = 17;
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
              case 14:
 | 
			
		||||
                _context.prev = 14;
 | 
			
		||||
                _context.t2 = _context['catch'](10);
 | 
			
		||||
                throw new Error('Was not able to parse type definition! (share.' + propertyname + ')');
 | 
			
		||||
 | 
			
		||||
              case 17:
 | 
			
		||||
                if (!(type.typeDefinition.parseArguments == null)) {
 | 
			
		||||
                  _context.next = 21;
 | 
			
		||||
                  break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                throw new Error(typeName + ' does not expect arguments!');
 | 
			
		||||
 | 
			
		||||
              case 21:
 | 
			
		||||
                args = typedef.parseArguments(args[0])[1];
 | 
			
		||||
 | 
			
		||||
              case 22:
 | 
			
		||||
                return _context.delegateYield(this.store.initType.call(this, id, args), 't3', 23);
 | 
			
		||||
 | 
			
		||||
              case 23:
 | 
			
		||||
                share[propertyname] = _context.t3;
 | 
			
		||||
                _context.next = 1;
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
              case 20:
 | 
			
		||||
              case 26:
 | 
			
		||||
                this.store.whenTransactionsFinished().then(callback);
 | 
			
		||||
 | 
			
		||||
              case 21:
 | 
			
		||||
              case 27:
 | 
			
		||||
              case 'end':
 | 
			
		||||
                return _context.stop();
 | 
			
		||||
            }
 | 
			
		||||
          }
 | 
			
		||||
        }, requestTransaction, this, [[7, 11]]);
 | 
			
		||||
        }, requestTransaction, this, [[10, 14]]);
 | 
			
		||||
      }));
 | 
			
		||||
    }
 | 
			
		||||
  }, {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user