merge textarea example

This commit is contained in:
Kevin Jahns 2017-08-24 14:46:16 +02:00
commit 5f29724578
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({
@ -13,16 +12,19 @@ Y({
name: 'websockets-client', name: 'websockets-client',
room: 'Textarea-example', room: 'Textarea-example',
// url: '//localhost:1234', // url: '//localhost:1234',
url: 'https://yjs-v13.herokuapp.com/', url: 'https://yjs-v13.herokuapp.com/'
// options: { transports: ['websocket'], upgrade: false } // options: { transports: ['websocket'], upgrade: false }
}, },
share: { share: {
textarea: 'Text' textarea: 'Text'
} },
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-15",
"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)
} }