Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Y
yjs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sweng-group-15
yjs
Commits
7753994e
Commit
7753994e
authored
9 years ago
by
Kevin Jahns
Browse files
Options
Downloads
Patches
Plain Diff
fixed bugs resolving from new init style
parent
70977942
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Struct.js
+15
-0
15 additions, 0 deletions
src/Struct.js
src/Transaction.js
+18
-7
18 additions, 7 deletions
src/Transaction.js
src/Utils.js
+9
-6
9 additions, 6 deletions
src/Utils.js
src/y.js
+9
-1
9 additions, 1 deletion
src/y.js
with
51 additions
and
14 deletions
src/Struct.js
+
15
−
0
View file @
7753994e
...
...
@@ -237,6 +237,14 @@ module.exports = function (Y/* :any */) {
id: this.os.getNextOpId()
}
*/
create
:
function
(
id
)
{
return
{
start
:
null
,
end
:
null
,
struct
:
'
List
'
,
id
:
id
}
},
encode
:
function
(
op
)
{
return
{
struct
:
'
List
'
,
...
...
@@ -303,6 +311,13 @@ module.exports = function (Y/* :any */) {
id: this.os.getNextOpId()
}
*/
create
:
function
(
id
)
{
return
{
id
:
id
,
map
:
{},
struct
:
'
Map
'
}
},
encode
:
function
(
op
)
{
return
{
struct
:
'
Map
'
,
...
...
This diff is collapsed.
Click to expand it.
src/Transaction.js
+
18
−
7
View file @
7753994e
...
...
@@ -99,6 +99,14 @@ module.exports = function (Y/* :any */) {
}
return
t
}
*
createType
(
typedefinition
)
{
var
structname
=
typedefinition
.
struct
var
id
=
this
.
store
.
getNextOpId
()
var
op
=
Y
.
Struct
[
structname
].
create
(
id
)
op
.
type
=
typedefinition
.
name
yield
*
this
.
applyCreatedOperations
([
op
])
return
yield
*
this
.
getType
(
id
)
}
/*
Apply operations that this user created (no remote ones!)
* does not check for Struct.*.requiredOps()
...
...
@@ -109,9 +117,11 @@ module.exports = function (Y/* :any */) {
for
(
var
i
=
0
;
i
<
ops
.
length
;
i
++
)
{
var
op
=
ops
[
i
]
yield
*
this
.
store
.
tryExecute
.
call
(
this
,
op
)
send
.
push
(
Y
.
Struct
[
op
.
struct
].
encode
(
op
))
if
(
op
.
id
==
null
||
op
.
id
[
0
]
!==
'
_
'
)
{
send
.
push
(
Y
.
Struct
[
op
.
struct
].
encode
(
op
))
}
}
if
(
!
this
.
store
.
y
.
connector
.
isDisconnected
())
{
// TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
if
(
!
this
.
store
.
y
.
connector
.
isDisconnected
()
&&
send
.
length
>
0
)
{
// TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
// is connected, and this is not going to be send in addOperation
this
.
store
.
y
.
connector
.
broadcast
({
type
:
'
update
'
,
...
...
@@ -565,11 +575,12 @@ module.exports = function (Y/* :any */) {
}
else
{
// need to generate this operation
if
(
this
.
store
.
_nextUserId
==
null
)
{
var
typename
=
id
[
1
].
split
(
'
_
'
)[
0
]
this
.
store
.
_nextUserId
=
id
yield
*
Y
[
typename
].
createType
.
call
(
this
)
delete
this
.
store
.
_nextUserId
return
yield
*
this
.
os
.
find
(
id
)
var
struct
=
id
[
1
].
split
(
'
_
'
)[
0
]
// this.store._nextUserId = id
var
op
=
Y
.
Struct
[
struct
].
create
(
id
)
yield
*
this
.
setOperation
(
op
)
// delete this.store._nextUserId
return
op
}
else
{
// Can only generate one operation at a time
return
null
...
...
This diff is collapsed.
Click to expand it.
src/Utils.js
+
9
−
6
View file @
7753994e
...
...
@@ -160,8 +160,8 @@ module.exports = function (Y /* : any*/) {
A wrapper for the definition of a custom type.
Every custom type must have three properties:
*
createType
-
Defines the model of a newly created custom type and returns the
type
*
struct
-
Structname of this
type
* initType
- Given a model, creates a custom type
* class
...
...
@@ -169,20 +169,23 @@ module.exports = function (Y /* : any*/) {
*/
class
CustomType
{
// eslint-disable-line
/* ::
createType
: any;
struct
: any;
initType: any;
class: Function;
name: String;
*/
constructor
(
def
)
{
if
(
def
.
createType
==
null
||
if
(
def
.
struct
==
null
||
def
.
initType
==
null
||
def
.
class
==
null
def
.
class
==
null
||
def
.
name
==
null
)
{
throw
new
Error
(
'
Custom type was not initialized correctly!
'
)
}
this
.
createType
=
def
.
createType
this
.
struct
=
def
.
struct
this
.
initType
=
def
.
initType
this
.
class
=
def
.
class
this
.
name
=
def
.
name
}
}
Y
.
utils
.
CustomType
=
CustomType
...
...
This diff is collapsed.
Click to expand it.
src/y.js
+
9
−
1
View file @
7753994e
...
...
@@ -115,7 +115,15 @@ class YConfig {
this
.
db
.
requestTransaction
(
function
*
requestTransaction
()
{
// create shared object
for
(
var
propertyname
in
opts
.
share
)
{
share
[
propertyname
]
=
yield
*
this
.
getType
([
'
_
'
,
opts
.
share
[
propertyname
]
+
'
_
'
+
propertyname
])
var
typename
=
opts
.
share
[
propertyname
]
var
id
=
[
'
_
'
,
Y
[
typename
].
struct
+
'
_
'
+
propertyname
]
var
op
=
yield
*
this
.
getOperation
(
id
)
if
(
op
.
type
!==
typename
)
{
// not already in the db
op
.
type
=
typename
yield
*
this
.
setOperation
(
op
)
}
share
[
propertyname
]
=
yield
*
this
.
getType
(
id
)
}
setTimeout
(
callback
,
0
)
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment