Compare commits

...

3 Commits

Author SHA1 Message Date
Kevin Jahns
9ed7e15d0f 13.0.0-14 2017-08-14 15:49:15 +02:00
Kevin Jahns
6e633d0bd9 lint 2017-08-14 15:41:37 +02:00
Kevin Jahns
e16195cb54 implement timeout for creating Yjs instance 2017-08-14 15:39:17 +02:00
3 changed files with 17 additions and 5 deletions

View File

@@ -2,7 +2,6 @@
// eslint-disable-next-line // eslint-disable-next-line
let search = new URLSearchParams(location.search) let search = new URLSearchParams(location.search)
let url = search.get('url')
// initialize a shared object. This function call returns a promise! // initialize a shared object. This function call returns a promise!
Y({ Y({
@@ -12,17 +11,20 @@ Y({
connector: { connector: {
name: 'websockets-client', name: 'websockets-client',
room: 'Textarea-example', room: 'Textarea-example',
url: url || 'http://127.0.0.1:1234' url: 'https://yjs-v13.herokuapp.com/'
}, },
sourceDir: '/bower_components', sourceDir: '/bower_components',
share: { share: {
textarea: 'Text', // y.share.textarea is of type Y.Text textarea: 'Text', // y.share.textarea is of type Y.Text
test: 'Array' test: 'Array'
} },
timeout: 5000 // reject if no connection was established within 5 seconds
}).then(function (y) { }).then(function (y) {
window.yTextarea = y window.yTextarea = y
// bind the textarea to a shared text element // bind the textarea to a shared text element
y.share.textarea.bind(document.getElementById('textfield')) y.share.textarea.bind(document.getElementById('textfield'))
// thats it.. // thats it..
}).catch(() => {
console.log('Something went wrong while creating the instance..')
}) })

View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-13", "version": "13.0.0-14",
"description": "A framework for real-time p2p shared editing on any data", "description": "A framework for real-time p2p shared editing on any data",
"main": "./y.node.js", "main": "./y.node.js",
"browser": "./y.js", "browser": "./y.js",

View File

@@ -139,10 +139,20 @@ export default function Y (opts/* :YOptions */) /* :Promise<YConfig> */ {
opts.share = Y.utils.copyObject(opts.share) opts.share = Y.utils.copyObject(opts.share)
Y.requestModules(modules).then(function () { Y.requestModules(modules).then(function () {
var yconfig = new YConfig(opts) var yconfig = new YConfig(opts)
let resolved = false
if (opts.timeout != null && opts.timeout >= 0) {
setTimeout(function () {
if (!resolved) {
reject(new Error('Yjs init timeout'))
yconfig.destroy()
}
}, opts.timeout)
}
yconfig.db.whenUserIdSet(function () { yconfig.db.whenUserIdSet(function () {
yconfig.init(function () { yconfig.init(function () {
resolved = true
resolve(yconfig) resolve(yconfig)
}) }, reject)
}) })
}).catch(reject) }).catch(reject)
} }