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
34f365cd
Commit
34f365cd
authored
8 years ago
by
Kevin Jahns
Browse files
Options
Downloads
Patches
Plain Diff
implemented support for synchronous type creation
parent
b3ba8e75
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/Database.js
+14
-7
14 additions, 7 deletions
src/Database.js
src/Utils.js
+15
-7
15 additions, 7 deletions
src/Utils.js
src/y.js
+1
-1
1 addition, 1 deletion
src/y.js
with
30 additions
and
15 deletions
src/Database.js
+
14
−
7
View file @
34f365cd
...
@@ -506,11 +506,16 @@ module.exports = function (Y /* :any */) {
...
@@ -506,11 +506,16 @@ module.exports = function (Y /* :any */) {
}
}
}
}
/*
/*
Get a type based on the id of its model.
Get a created/initialized type.
If it does not exist yes, create it.
TODO: delete type from store.initializedTypes[id] when corresponding id was deleted!
*/
*/
*
getType
(
id
,
args
)
{
getType
(
id
)
{
return
this
.
initializedTypes
[
JSON
.
stringify
(
id
)]
}
/*
Init type. This is called when a remote operation is retrieved, and transformed to a type
TODO: delete type from store.initializedTypes[id] when corresponding id was deleted!
*/
*
initType
(
id
,
args
)
{
var
sid
=
JSON
.
stringify
(
id
)
var
sid
=
JSON
.
stringify
(
id
)
var
t
=
this
.
store
.
initializedTypes
[
sid
]
var
t
=
this
.
store
.
initializedTypes
[
sid
]
if
(
t
==
null
)
{
if
(
t
==
null
)
{
...
@@ -522,6 +527,9 @@ module.exports = function (Y /* :any */) {
...
@@ -522,6 +527,9 @@ module.exports = function (Y /* :any */) {
}
}
return
t
return
t
}
}
/*
Create type. This is called when the local user creates a type (which is a synchronous action)
*/
createType
(
typedefinition
,
id
)
{
createType
(
typedefinition
,
id
)
{
var
structname
=
typedefinition
[
0
].
struct
var
structname
=
typedefinition
[
0
].
struct
id
=
id
||
this
.
getNextOpId
(
1
)
id
=
id
||
this
.
getNextOpId
(
1
)
...
@@ -534,16 +542,15 @@ module.exports = function (Y /* :any */) {
...
@@ -534,16 +542,15 @@ module.exports = function (Y /* :any */) {
}
}
*/
*/
this
.
requestTransaction
(
function
*
()
{
this
.
requestTransaction
(
function
*
()
{
if
(
op
[
0
]
===
'
_
'
)
{
if
(
op
.
id
[
0
]
===
'
_
'
)
{
yield
*
this
.
setOperation
(
op
)
yield
*
this
.
setOperation
(
op
)
}
else
{
}
else
{
yield
*
this
.
applyCreatedOperations
([
op
])
yield
*
this
.
applyCreatedOperations
([
op
])
}
}
})
})
var
t
=
Y
[
op
.
type
].
typeDefinition
.
create
New
Type
(
this
,
op
)
var
t
=
Y
[
op
.
type
].
typeDefinition
.
createType
(
this
,
op
,
typedefinition
[
1
]
)
this
.
initializedTypes
[
JSON
.
stringify
(
op
.
id
)]
=
t
this
.
initializedTypes
[
JSON
.
stringify
(
op
.
id
)]
=
t
return
t
return
t
//return yield* this.getType(id, typedefinition[1])
}
}
}
}
Y
.
AbstractDatabase
=
AbstractDatabase
Y
.
AbstractDatabase
=
AbstractDatabase
...
...
This diff is collapsed.
Click to expand it.
src/Utils.js
+
15
−
7
View file @
34f365cd
...
@@ -457,6 +457,14 @@ module.exports = function (Y /* : any*/) {
...
@@ -457,6 +457,14 @@ module.exports = function (Y /* : any*/) {
}
}
Y
.
utils
.
EventHandler
=
EventHandler
Y
.
utils
.
EventHandler
=
EventHandler
/*
Default class of custom types!
*/
class
CustomType
{
}
Y
.
utils
.
CustomType
=
CustomType
/*
/*
A wrapper for the definition of a custom type.
A wrapper for the definition of a custom type.
Every custom type must have three properties:
Every custom type must have three properties:
...
@@ -468,7 +476,7 @@ module.exports = function (Y /* : any*/) {
...
@@ -468,7 +476,7 @@ module.exports = function (Y /* : any*/) {
* class
* class
- the constructor of the custom type (e.g. in order to inherit from a type)
- the constructor of the custom type (e.g. in order to inherit from a type)
*/
*/
class
CustomType
{
// eslint-disable-line
class
CustomType
Definition
{
// eslint-disable-line
/* ::
/* ::
struct: any;
struct: any;
initType: any;
initType: any;
...
@@ -480,13 +488,13 @@ module.exports = function (Y /* : any*/) {
...
@@ -480,13 +488,13 @@ module.exports = function (Y /* : any*/) {
def
.
initType
==
null
||
def
.
initType
==
null
||
def
.
class
==
null
||
def
.
class
==
null
||
def
.
name
==
null
||
def
.
name
==
null
||
def
.
create
New
Type
==
null
def
.
createType
==
null
)
{
)
{
throw
new
Error
(
'
Custom type was not initialized correctly!
'
)
throw
new
Error
(
'
Custom type was not initialized correctly!
'
)
}
}
this
.
struct
=
def
.
struct
this
.
struct
=
def
.
struct
this
.
initType
=
def
.
initType
this
.
initType
=
def
.
initType
this
.
create
New
Type
=
def
.
create
New
Type
this
.
createType
=
def
.
createType
this
.
class
=
def
.
class
this
.
class
=
def
.
class
this
.
name
=
def
.
name
this
.
name
=
def
.
name
if
(
def
.
appendAdditionalInfo
!=
null
)
{
if
(
def
.
appendAdditionalInfo
!=
null
)
{
...
@@ -498,13 +506,13 @@ module.exports = function (Y /* : any*/) {
...
@@ -498,13 +506,13 @@ module.exports = function (Y /* : any*/) {
this
.
parseArguments
.
typeDefinition
=
this
this
.
parseArguments
.
typeDefinition
=
this
}
}
}
}
Y
.
utils
.
CustomType
=
CustomType
Y
.
utils
.
CustomType
Definition
=
CustomType
Definition
Y
.
utils
.
isTypeDefinition
=
function
isTypeDefinition
(
v
)
{
Y
.
utils
.
isTypeDefinition
=
function
isTypeDefinition
(
v
)
{
if
(
v
!=
null
)
{
if
(
v
!=
null
)
{
if
(
v
instanceof
Y
.
utils
.
CustomType
)
return
[
v
]
if
(
v
instanceof
Y
.
utils
.
CustomType
Definition
)
return
[
v
]
else
if
(
v
.
constructor
===
Array
&&
v
[
0
]
instanceof
Y
.
utils
.
CustomType
)
return
v
else
if
(
v
.
constructor
===
Array
&&
v
[
0
]
instanceof
Y
.
utils
.
CustomType
Definition
)
return
v
else
if
(
v
instanceof
Function
&&
v
.
typeDefinition
instanceof
Y
.
utils
.
CustomType
)
return
[
v
.
typeDefinition
]
else
if
(
v
instanceof
Function
&&
v
.
typeDefinition
instanceof
Y
.
utils
.
CustomType
Definition
)
return
[
v
.
typeDefinition
]
}
}
return
false
return
false
}
}
...
...
This diff is collapsed.
Click to expand it.
src/y.js
+
1
−
1
View file @
34f365cd
...
@@ -14,7 +14,7 @@ module.exports = Y
...
@@ -14,7 +14,7 @@ module.exports = Y
Y
.
requiringModules
=
requiringModules
Y
.
requiringModules
=
requiringModules
Y
.
extend
=
function
(
name
,
value
)
{
Y
.
extend
=
function
(
name
,
value
)
{
if
(
value
instanceof
Y
.
utils
.
CustomType
)
{
if
(
value
instanceof
Y
.
utils
.
CustomType
Definition
)
{
Y
[
name
]
=
value
.
parseArguments
Y
[
name
]
=
value
.
parseArguments
}
else
{
}
else
{
Y
[
name
]
=
value
Y
[
name
]
=
value
...
...
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