Toggle navigation
Toggle navigation
This project
Loading...
Sign in
arcs
/
arcs.js
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
3
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jean-Yves Didier
2019-12-10 00:39:07 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c9d251a9376ba2c9626ed7a6d48f9a1d758ceb3a
c9d251a9
1 parent
2092a8f5
started to modify module system; is not runnable yet
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
87 deletions
src/arcs.js
src/arcs_browser.js
src/arcs_module.js
src/context.js
src/exports.js
src/arcs.js
View file @
c9d251a
...
...
@@ -22,19 +22,11 @@ var ARCS = ARCS || {};
* Helper functions to determine environment
* ***************************************************************************/
/**
* @return {boolean} true if ARCS is run in a node.js environment
*/
ARCS
.
isInNode
=
function
()
{
return
(
typeof
require
===
'function'
&&
require
.
resolve
);
return
(
typeof
require
===
'function'
&&
require
.
resolve
);
};
/**
* @return {boolean} true if ARCS is run with require.js
*/
ARCS
.
isInRequire
=
function
()
{
return
(
typeof
define
===
'function'
&&
define
.
amd
);
};
...
...
src/arcs_browser.js
View file @
c9d251a
...
...
@@ -4,6 +4,10 @@
* @file
*/
// basically, here we start by importing the module ARCS
import
ARCS
from
'./arcs.js'
;
console
.
log
(
"Bootstrapping ARCS..."
);
var
baseUrl
,
appDescription
,
requireMarkup
,
xhr
;
...
...
@@ -14,34 +18,15 @@ if (requireMarkup !== undefined) {
appDescription
=
requireMarkup
.
dataset
.
arcsapp
||
"arcsapp.json"
;
}
// do not move these lines: xhr.open must be performed before require
// changes paths.
xhr
=
new
XMLHttpRequest
();
xhr
.
open
(
'GET'
,
appDescription
,
true
);
xhr
.
overrideMimeType
(
"application/json"
);
xhr
.
onerror
=
function
(
e
)
{
console
.
error
(
"[ARCS] Failed to get app description ("
,
appDescription
,
"):"
,
e
.
target
.
status
,
e
.
message
);
};
require
([
'arcs'
],
function
(
ARCS
)
{
//console.log(ARCS);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
&&
(
xhr
.
status
==
200
||
xhr
.
status
==
0
))
{
try
{
console
.
log
(
"ARCS application description loaded"
);
var
applicationObject
=
JSON
.
parse
(
xhr
.
responseText
);
if
(
baseUrl
)
{
require
.
config
(
{
baseUrl
:
baseUrl
});
}
var
aap
=
new
ARCS
.
Application
();
aap
.
import
(
applicationObject
);
console
.
log
(
"Starting application..."
);
aap
.
start
();
}
catch
(
e
)
{
console
.
error
(
"[ARCS] Error while parsing JSON:"
,
e
);
}
}
};
xhr
.
send
();
});
const
appDescription
=
await
fetch
(
appDescription
);
const
applicationObject
=
await
appDescription
.
json
();
console
.
log
(
"ARCS application description loaded"
);
if
(
baseUrl
)
{
require
.
config
(
{
baseUrl
:
baseUrl
});
}
var
aap
=
new
ARCS
.
Application
();
aap
.
import
(
applicationObject
);
console
.
log
(
"Starting application..."
);
aap
.
start
();
...
...
src/arcs_module.js
View file @
c9d251a
...
...
@@ -8,6 +8,13 @@
* @param deps {mixed[]} dependencies
*/
// TODO arcs_module seems to be not needed anymore!!!!
// more cunning, this time, we export an arcs_module function
// that we call later!
// still we need to do something about it in order to register
// components.
// in fact factories should be registered in load library.
// reimplementation using native promises
arcs_module
=
function
(
moduleDefinition
,
deps
)
{
var
storeComponents
,
i
;
...
...
src/context.js
View file @
c9d251a
...
...
@@ -39,7 +39,7 @@ ARCS.Context = function( ctx ) {
}
//! TODO use fetch API?
loadDataFile
=
function
(
fileName
)
{
var
dataPromise
;
...
...
@@ -75,36 +75,17 @@ ARCS.Context = function( ctx ) {
}
};
//! TODO not needed anymore?
this
.
addLibraryPromise
=
function
(
p
)
{
depLibPromises
.
push
(
p
);
};
promiseLibrary
=
function
(
libName
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
if
(
libName
.
substr
(
-
3
)
===
'.js'
)
{
reject
(
libName
);
}
if
(
ARCS
.
isInNode
())
{
if
(
require
(
"./"
+
libraries
[
i
]
+
".js"
)
===
undefined
)
{
reject
(
libName
);
}
else
{
resolve
();
}
}
else
{
require
([
libName
],
function
()
{
resolve
();
},
function
(
err
)
{
reject
(
libName
,
err
);
}
);
}
});
return
import
(
libName
);
};
//! TODO modify loadLibraries and loadLibrary to directly register
// factories so that arcs_module is not needed anymore ?
loadLibraries
=
function
()
{
var
i
;
// we will use different instances of require either the one of node
...
...
@@ -113,7 +94,8 @@ ARCS.Context = function( ctx ) {
var
res
=
[];
for
(
i
=
0
;
i
<
libraries
.
length
;
i
++
)
{
res
.
push
(
promiseLibrary
(
libraries
[
i
]));
//! TODO
res
.
push
(
import
(
libraries
[
i
]));
}
return
Promise
.
all
(
res
);
};
...
...
@@ -301,6 +283,7 @@ ARCS.Context = function( ctx ) {
// this should return a promise !
this
.
instanciate
=
function
()
{
//! TODO
return
loadLibraries
().
then
(
function
()
{
return
Promise
.
all
(
depLibPromises
);
})
.
then
(
instanciateComponents
)
.
catch
(
function
(
msg
)
{
console
.
log
(
"[ARCS] Trouble instanciating context"
,
msg
);
});
...
...
src/exports.js
View file @
c9d251a
// no longer needed with the use of imports
// ARCS is then defined as a node.js module
if
(
!
ARCS
.
isInNode
())
{
var
exports
=
{};
}
exports
.
Component
=
ARCS
.
Component
;
exports
.
Connection
=
ARCS
.
Connection
;
exports
.
Invocation
=
ARCS
.
Invocation
;
exports
.
Statemachine
=
ARCS
.
Statemachine
;
exports
.
Sheet
=
ARCS
.
Sheet
;
exports
.
Application
=
ARCS
.
Application
;
exports
.
EventLogicParser
=
ARCS
.
EventLogicParser
;
exports
.
TransitionSystem
=
ARCS
.
TransitionSystem
;
exports
.
isInNode
=
ARCS
.
isInNode
;
exports
.
isInRequire
=
ARCS
.
isInRequire
;
// hack for require.js
// ARCS is then defined as a require.js module.
if
(
ARCS
.
isInRequire
())
{
//console.log("module ARCS in require.js");
define
(
exports
);
}
export
default
ARCS
;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment