outsourced examples
This commit is contained in:
parent
e9ac59dcf8
commit
f58889a05d
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ build_test
|
|||||||
.validate.json
|
.validate.json
|
||||||
/y.js
|
/y.js
|
||||||
/y.js.map
|
/y.js.map
|
||||||
|
/y-*
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<button id="button">Disconnect</button>
|
|
||||||
<h1 id="contenteditable" contentEditable></h1>
|
|
||||||
<textarea style="width:80%;" rows=40 id="textfield"></textarea>
|
|
||||||
|
|
||||||
<script src="../../node_modules/simplewebrtc/simplewebrtc.bundle.js"></script>
|
|
||||||
<script src="../../y.js"></script>
|
|
||||||
<script src="./index.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,50 +0,0 @@
|
|||||||
/* global Y */
|
|
||||||
|
|
||||||
// create a shared object. This function call will return a promise!
|
|
||||||
Y({
|
|
||||||
db: {
|
|
||||||
name: 'IndexedDB',
|
|
||||||
namespace: 'offlineEditingDemo'
|
|
||||||
},
|
|
||||||
connector: {
|
|
||||||
name: 'WebRTC',
|
|
||||||
room: 'offlineEditingDemo',
|
|
||||||
debug: true
|
|
||||||
}
|
|
||||||
}).then(function (yconfig) {
|
|
||||||
// yconfig holds all the information about the shared object
|
|
||||||
window.yconfig = yconfig
|
|
||||||
// yconfig.root holds the shared element
|
|
||||||
window.y = yconfig.root
|
|
||||||
|
|
||||||
// now we bind the textarea and the contenteditable h1 element
|
|
||||||
// to a shared element
|
|
||||||
var textarea = document.getElementById('textfield')
|
|
||||||
var contenteditable = document.getElementById('contenteditable')
|
|
||||||
yconfig.root.observePath(['text'], function (text) {
|
|
||||||
// every time the 'text' property of the yconfig.root changes,
|
|
||||||
// this function is called. Then we bind it to the html elements
|
|
||||||
if (text != null) {
|
|
||||||
// when the text property is deleted, text may be undefined!
|
|
||||||
// This is why we have to check if text exists..
|
|
||||||
text.bind(textarea)
|
|
||||||
text.bind(contenteditable)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// create a shared TextBind
|
|
||||||
var textpromise = yconfig.root.get('text')
|
|
||||||
if (textpromise == null) {
|
|
||||||
yconfig.root.set('text', Y.TextBind)
|
|
||||||
}
|
|
||||||
// We also provide a button for disconnecting/reconnecting the shared element
|
|
||||||
var button = document.querySelector('#button')
|
|
||||||
button.onclick = function () {
|
|
||||||
if (button.innerText === 'Disconnect') {
|
|
||||||
yconfig.disconnect()
|
|
||||||
button.innerText = 'Reconnect'
|
|
||||||
} else {
|
|
||||||
yconfig.reconnect()
|
|
||||||
button.innerText = 'Disconnect'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
@ -1,12 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<body>
|
|
||||||
<button id="button">Disconnect</button>
|
|
||||||
<h1 id="contenteditable" contentEditable></h1>
|
|
||||||
<textarea style="width:80%;" rows=40 id="textfield"></textarea>
|
|
||||||
|
|
||||||
<script src="../../node_modules/simplewebrtc/simplewebrtc.bundle.js"></script>
|
|
||||||
<script src="../../y.js"></script>
|
|
||||||
<script src="./index.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,47 +0,0 @@
|
|||||||
/* global Y */
|
|
||||||
|
|
||||||
// create a shared object. This function call will return a promise!
|
|
||||||
Y({
|
|
||||||
db: {
|
|
||||||
name: 'Memory'
|
|
||||||
},
|
|
||||||
connector: {
|
|
||||||
name: 'WebRTC',
|
|
||||||
room: 'TextBindDemo',
|
|
||||||
debug: true
|
|
||||||
}
|
|
||||||
}).then(function (yconfig) {
|
|
||||||
// yconfig holds all the information about the shared object
|
|
||||||
window.yconfig = yconfig
|
|
||||||
// yconfig.root holds the shared element
|
|
||||||
window.y = yconfig.root
|
|
||||||
|
|
||||||
// now we bind the textarea and the contenteditable h1 element
|
|
||||||
// to a shared element
|
|
||||||
var textarea = document.getElementById('textfield')
|
|
||||||
var contenteditable = document.getElementById('contenteditable')
|
|
||||||
yconfig.root.observePath(['text'], function (text) {
|
|
||||||
// every time the 'text' property of the yconfig.root changes,
|
|
||||||
// this function is called. Then we bind it to the html elements
|
|
||||||
if (text != null) {
|
|
||||||
// when the text property is deleted, text may be undefined!
|
|
||||||
// This is why we have to check if text exists..
|
|
||||||
text.bind(textarea)
|
|
||||||
text.bind(contenteditable)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// create a shared TextBind
|
|
||||||
yconfig.root.set('text', Y.TextBind)
|
|
||||||
|
|
||||||
// We also provide a button for disconnecting/reconnecting the shared element
|
|
||||||
var button = document.querySelector('#button')
|
|
||||||
button.onclick = function () {
|
|
||||||
if (button.innerText === 'Disconnect') {
|
|
||||||
yconfig.disconnect()
|
|
||||||
button.innerText = 'Reconnect'
|
|
||||||
} else {
|
|
||||||
yconfig.reconnect()
|
|
||||||
button.innerText = 'Disconnect'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
2
dist
2
dist
@ -1 +1 @@
|
|||||||
Subproject commit 33b7588497538d07a514b3be4cfe53e26fc366a4
|
Subproject commit e2e89e198f47689fe6df908c0ea1cef6d800be0d
|
52
gulpfile.js
52
gulpfile.js
@ -44,15 +44,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var gulp = require('gulp')
|
var gulp = require('gulp')
|
||||||
var sourcemaps = require('gulp-sourcemaps')
|
|
||||||
var babel = require('gulp-babel')
|
|
||||||
var uglify = require('gulp-uglify')
|
|
||||||
var minimist = require('minimist')
|
var minimist = require('minimist')
|
||||||
var jasmine = require('gulp-jasmine')
|
|
||||||
var jasmineBrowser = require('gulp-jasmine-browser')
|
|
||||||
var concat = require('gulp-concat')
|
var concat = require('gulp-concat')
|
||||||
var watch = require('gulp-watch')
|
|
||||||
var shell = require('gulp-shell')
|
|
||||||
var $ = require('gulp-load-plugins')()
|
var $ = require('gulp-load-plugins')()
|
||||||
|
|
||||||
var options = minimist(process.argv.slice(2), {
|
var options = minimist(process.argv.slice(2), {
|
||||||
@ -102,16 +95,16 @@ if (options.regenerator) {
|
|||||||
|
|
||||||
gulp.task('deploy:build', function () {
|
gulp.task('deploy:build', function () {
|
||||||
return gulp.src(files.src)
|
return gulp.src(files.src)
|
||||||
.pipe(sourcemaps.init())
|
.pipe($.sourcemaps.init())
|
||||||
.pipe(concat('y.js'))
|
.pipe(concat('y.js'))
|
||||||
.pipe(babel({
|
.pipe($.babel({
|
||||||
loose: 'all',
|
loose: 'all',
|
||||||
modules: 'ignore',
|
modules: 'ignore',
|
||||||
experimental: true
|
experimental: true
|
||||||
}))
|
}))
|
||||||
.pipe(uglify())
|
.pipe($.uglify())
|
||||||
.pipe(sourcemaps.write('.'))
|
.pipe($.sourcemaps.write('./dist/'))
|
||||||
.pipe(gulp.dest('.'))
|
.pipe(gulp.dest('./dist/'))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('deploy:updateSubmodule', function () {
|
gulp.task('deploy:updateSubmodule', function () {
|
||||||
@ -119,19 +112,19 @@ gulp.task('deploy:updateSubmodule', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('deploy:copy', function () {
|
gulp.task('deploy:copy', function () {
|
||||||
return gulp.src(['./y.js', './y.js.map', './README.md', 'package.json', 'LICENSE'])
|
return gulp.src(['README.md'], {base: '.'})
|
||||||
.pipe(gulp.dest('./dist/'))
|
.pipe(gulp.dest('dist/'))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('deploy:bump', function () {
|
gulp.task('deploy:bump', function () {
|
||||||
return gulp.src('./package.json')
|
return gulp.src(['./package.json', './dist/package.json'], {base: '.'})
|
||||||
.pipe($.bump({type: 'patch'}))
|
.pipe($.bump({type: 'patch'}))
|
||||||
.pipe(gulp.dest('./'))
|
.pipe(gulp.dest('./'))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('deploy', ['test', 'deploy:updateSubmodule', 'deploy:bump', 'deploy:build', 'deploy:copy'], function () {
|
gulp.task('deploy', ['test', 'deploy:updateSubmodule', 'deploy:bump', 'deploy:build', 'deploy:copy'], function () {
|
||||||
return gulp.src('./package.json', {read: false})
|
return gulp.src('./package.json', {read: false})
|
||||||
.pipe(shell([
|
.pipe($.shell([
|
||||||
'standard',
|
'standard',
|
||||||
'echo "Deploying version <%= getVersion(file.path) %>"',
|
'echo "Deploying version <%= getVersion(file.path) %>"',
|
||||||
'git pull',
|
'git pull',
|
||||||
@ -161,16 +154,16 @@ gulp.task('build:test', function () {
|
|||||||
babelOptions.blacklist = 'regenerator'
|
babelOptions.blacklist = 'regenerator'
|
||||||
}
|
}
|
||||||
gulp.src(files.src)
|
gulp.src(files.src)
|
||||||
.pipe(sourcemaps.init())
|
.pipe($.sourcemaps.init())
|
||||||
.pipe(concat('y.js'))
|
.pipe(concat('y.js'))
|
||||||
.pipe(babel(babelOptions))
|
.pipe($.babel(babelOptions))
|
||||||
.pipe(sourcemaps.write())
|
.pipe($.sourcemaps.write())
|
||||||
.pipe(gulp.dest('.'))
|
.pipe(gulp.dest('.'))
|
||||||
|
|
||||||
return gulp.src('src/**/*.js')
|
return gulp.src('src/**/*.js')
|
||||||
.pipe(sourcemaps.init())
|
.pipe($.sourcemaps.init())
|
||||||
.pipe(babel(babelOptions))
|
.pipe($.babel(babelOptions))
|
||||||
.pipe(sourcemaps.write())
|
.pipe($.sourcemaps.write())
|
||||||
.pipe(gulp.dest('build'))
|
.pipe(gulp.dest('build'))
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -182,9 +175,9 @@ gulp.task('dev:browser', ['build:test'], function () {
|
|||||||
gulp.watch('src/**/*.js', ['build:test'])
|
gulp.watch('src/**/*.js', ['build:test'])
|
||||||
|
|
||||||
gulp.src(files.test)
|
gulp.src(files.test)
|
||||||
.pipe(watch(['build/**/*.js']))
|
.pipe($.watch(['build/**/*.js']))
|
||||||
.pipe(jasmineBrowser.specRunner())
|
.pipe($.jasmineBrowser.specRunner())
|
||||||
.pipe(jasmineBrowser.server({port: options.testport}))
|
.pipe($.jasmineBrowser.server({port: options.testport}))
|
||||||
})
|
})
|
||||||
|
|
||||||
gulp.task('dev', ['build:test'], function () {
|
gulp.task('dev', ['build:test'], function () {
|
||||||
@ -192,13 +185,20 @@ gulp.task('dev', ['build:test'], function () {
|
|||||||
gulp.start('dev:node')
|
gulp.start('dev:node')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
gulp.task('copy:dist', ['deploy:build'])
|
||||||
|
|
||||||
|
gulp.task('dev:Examples', ['copy:dist'], function () {
|
||||||
|
gulp.watch('src/**/*.js', ['copy:dist'])
|
||||||
|
return $.serve('dist/Examples')()
|
||||||
|
})
|
||||||
|
|
||||||
gulp.task('test', ['build:test'], function () {
|
gulp.task('test', ['build:test'], function () {
|
||||||
var testfiles = files.test
|
var testfiles = files.test
|
||||||
if (typeof Promise === 'undefined') {
|
if (typeof Promise === 'undefined') {
|
||||||
testfiles.concat(['src/polyfills.js'])
|
testfiles.concat(['src/polyfills.js'])
|
||||||
}
|
}
|
||||||
return gulp.src(testfiles)
|
return gulp.src(testfiles)
|
||||||
.pipe(jasmine({
|
.pipe($.jasmine({
|
||||||
verbose: true,
|
verbose: true,
|
||||||
includeStuckTrace: true
|
includeStuckTrace: true
|
||||||
}))
|
}))
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "yjs",
|
"name": "yjs",
|
||||||
"version": "0.6.23",
|
"version": "0.6.25",
|
||||||
"description": "A framework for real-time p2p shared editing on arbitrary complex data types",
|
"description": "A framework for real-time p2p shared editing on arbitrary complex data types",
|
||||||
"main": "y.js",
|
"main": "y.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -52,6 +52,7 @@
|
|||||||
"gulp-jasmine": "^2.0.1",
|
"gulp-jasmine": "^2.0.1",
|
||||||
"gulp-jasmine-browser": "^0.2.3",
|
"gulp-jasmine-browser": "^0.2.3",
|
||||||
"gulp-load-plugins": "^1.0.0",
|
"gulp-load-plugins": "^1.0.0",
|
||||||
|
"gulp-serve": "^1.2.0",
|
||||||
"gulp-shell": "^0.5.1",
|
"gulp-shell": "^0.5.1",
|
||||||
"gulp-sourcemaps": "^1.5.2",
|
"gulp-sourcemaps": "^1.5.2",
|
||||||
"gulp-tag-version": "^1.3.0",
|
"gulp-tag-version": "^1.3.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user