implemented es6 import utility function (Y.extend(module) === module(Y))
This commit is contained in:
parent
f93d7b1e70
commit
08bcdfb008
13
README.md
13
README.md
@ -71,6 +71,19 @@ require('y-text')(Y)
|
|||||||
// do the same for all modules you want to use
|
// do the same for all modules you want to use
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### ES6 Syntax
|
||||||
|
```
|
||||||
|
import Y from 'yjs'
|
||||||
|
import yArray from 'y-array'
|
||||||
|
import yWebsocketsClient from 'y-webrtc'
|
||||||
|
import yMemory from 'y-memory'
|
||||||
|
import yArray from 'y-array'
|
||||||
|
import yMap from 'y-map'
|
||||||
|
import yText from 'y-text'
|
||||||
|
// ..
|
||||||
|
Y.extend(yArray, yWebsocketsClient, yMemory, yArray, yMap, yText /*, .. */)
|
||||||
|
```
|
||||||
|
|
||||||
# Text editing example
|
# Text editing example
|
||||||
Install dependencies
|
Install dependencies
|
||||||
```
|
```
|
||||||
|
25
src/y.js
25
src/y.js
@ -14,14 +14,25 @@ module.exports = Y
|
|||||||
Y.requiringModules = requiringModules
|
Y.requiringModules = requiringModules
|
||||||
|
|
||||||
Y.extend = function (name, value) {
|
Y.extend = function (name, value) {
|
||||||
if (value instanceof Y.utils.CustomTypeDefinition) {
|
if (arguments.length === 2 && typeof name === 'string') {
|
||||||
Y[name] = value.parseArguments
|
if (value instanceof Y.utils.CustomTypeDefinition) {
|
||||||
|
Y[name] = value.parseArguments
|
||||||
|
} else {
|
||||||
|
Y[name] = value
|
||||||
|
}
|
||||||
|
if (requiringModules[name] != null) {
|
||||||
|
requiringModules[name].resolve()
|
||||||
|
delete requiringModules[name]
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Y[name] = value
|
for (var i = 0; i < arguments.length; i++) {
|
||||||
}
|
var f = arguments[i]
|
||||||
if (requiringModules[name] != null) {
|
if (typeof f === 'function') {
|
||||||
requiringModules[name].resolve()
|
f(Y)
|
||||||
delete requiringModules[name]
|
} else {
|
||||||
|
throw new Error('Expected function!')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user