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 10:51:53 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
25b1515e2b60a04bf393c7d7f36a7cb59d658e79
25b1515e
1 parent
aa327533
update for minification in order to support es6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
91 deletions
Gruntfile.js
build/arcs.js
components/loop.js
package.json
src/context.js
tests/loop/loop.html
Gruntfile.js
View file @
25b1515
...
...
@@ -43,12 +43,9 @@ module.exports = function (grunt) {
}
}
},
ugl
ify
:
{
file_min
ify
:
{
build
:
{
options
:
{
banner
:
'/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
files
:
{
files
:
{
'build/arcs.min.js'
:
[
'build/arcs.js'
],
...
...
@@ -58,9 +55,28 @@ module.exports = function (grunt) {
'build/arcseditor.min.js'
:
[
'build/arcseditor.js'
]
}
}
},
//uglify: {
// build: {
// options: {
// banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
// },
// files: {
/* 'build/arcs.min.js': [
'build/arcs.js'
],
'build/arcs_browser.js': [
'src/arcs_browser.js'
],
'build/arcseditor.min.js': [
'build/arcseditor.js'
]
}
}
},*/
bower
:
{
options
:
{
verbose
:
true
,
...
...
@@ -112,7 +128,8 @@ module.exports = function (grunt) {
});
// Load the plugin that provides the "uglify" task.
grunt
.
loadNpmTasks
(
'grunt-contrib-uglify'
);
//grunt.loadNpmTasks('grunt-contrib-uglify');
grunt
.
loadNpmTasks
(
'grunt-file-minify'
);
grunt
.
loadNpmTasks
(
'grunt-contrib-concat'
);
grunt
.
loadNpmTasks
(
'grunt-jsdoc'
);
grunt
.
loadNpmTasks
(
'grunt-jslint'
);
...
...
@@ -120,7 +137,7 @@ module.exports = function (grunt) {
// Default task(s).
grunt
.
registerTask
(
'default'
,
[
'concat'
,
'
uglify'
]);
grunt
.
registerTask
(
'default'
,
[
'concat'
,
'
file_minify'
/*'uglify'*/
]);
grunt
.
registerTask
(
'lint'
,
[
'jslint'
]);
grunt
.
registerTask
(
'doc'
,
[
'jsdoc'
]);
};
...
...
build/arcs.js
View file @
25b1515
...
...
@@ -22,22 +22,14 @@ 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
);
};
/******************************************************************************
* Component implementation
...
...
@@ -271,8 +263,8 @@ ARCS.Context = function( ctx ) {
}
loadDataFile
=
function
(
fileName
)
{
//! TODO use fetch API?
loadDataFile
=
async
function
(
fileName
)
{
var
dataPromise
;
if
(
ARCS
.
isInNode
())
{
...
...
@@ -285,58 +277,22 @@ ARCS.Context = function( ctx ) {
}
});
}
else
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
client
=
new
XMLHttpRequest
();
client
.
open
(
'GET'
,
fileName
,
true
);
client
.
overrideMimeType
(
"application/json"
);
client
.
send
();
client
.
onload
=
function
()
{
if
(
this
.
status
>=
200
&&
this
.
status
<
300
)
{
resolve
(
JSON
.
parse
(
this
.
responseText
));
}
else
{
console
.
error
(
this
.
statusText
);
reject
(
this
.
statusText
);
}
};
client
.
onerror
=
function
()
{
console
.
error
(
this
.
statusText
);
reject
(
this
.
statusText
);
};
});
var
client
=
await
fetch
(
fileName
);
return
client
.
json
();
}
};
//! 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
...
...
@@ -345,7 +301,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
);
};
...
...
@@ -533,6 +490,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
);
});
...
...
@@ -2109,6 +2067,13 @@ ARCS.Application.slot("finish");
* @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
;
...
...
@@ -2189,26 +2154,6 @@ arcs_module = function(moduleDefinition, deps) {
);
}
// 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
...
...
components/loop.js
View file @
25b1515
...
...
@@ -5,7 +5,15 @@
* @file
*/
arcs_module
(
function
(
ARCS
)
{
// TODO first strategy: import ARCS and export components
// TODO second strategy: make an anonymous function to export
// in any case, arcs_module disappears
//! TODO to comment or uncomment (maybe)
// imports ARCS from '../build/arcs.js';
function
(
ARCS
)
{
var
Loop
,
DisplayInt
,
Sum
;
/** @exports loop */
//console.log("loop: ", ARCS);
...
...
@@ -103,4 +111,5 @@ arcs_module(function (ARCS) {
// ARCS.Component.create
return
{
Loop
:
Loop
,
DisplayInt
:
DisplayInt
,
Sum
:
Sum
};
});
//! TODO comment or uncomment (maybe)
}
...
...
package.json
View file @
25b1515
...
...
@@ -17,6 +17,7 @@
"grunt"
:
">=0.4.5"
,
"grunt-jslint"
:
">=1.1.12"
,
"grunt-contrib-uglify"
:
">=0.5.1"
,
"grunt-file-minify"
:
">=1.0.0"
,
"grunt-jsdoc"
:
">=0.5.6"
,
"grunt-bower-task"
:
">=0.4.0"
,
"grunt-contrib-concat"
:
">=0.5.0"
...
...
src/context.js
View file @
25b1515
...
...
@@ -40,7 +40,7 @@ ARCS.Context = function( ctx ) {
}
//! TODO use fetch API?
loadDataFile
=
function
(
fileName
)
{
loadDataFile
=
async
function
(
fileName
)
{
var
dataPromise
;
if
(
ARCS
.
isInNode
())
{
...
...
tests/loop/loop.html
View file @
25b1515
<html>
<head>
<title>
ARCS engine
</title>
<script
data-
main=
"../../build/arcs_browser
"
data-base-url=
"../..
"
data-arcsapp=
"arcsapp.json"
src=
"../../deps/requirejs/require.js
"
>
</script>
<script
data-
base-url=
"../..
"
data-arcsapp=
"arcsapp.json
"
type=
"module"
src=
"../../build/arcs_browser
"
>
</script>
</head>
<body>
<h1>
ARCS in Web Browser
</h1>
...
...
Please
register
or
login
to post a comment