Skip to content

Commit 40a3af0

Browse files
committed
Publish version 0.4.6
1 parent 9fae39c commit 40a3af0

File tree

6 files changed

+91
-31
lines changed

6 files changed

+91
-31
lines changed

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ecore.js",
33
"main": "dist/ecore.js",
4-
"version": "0.4.5",
4+
"version": "0.4.6",
55
"homepage": "https://github.com/ghillairet/ecore.js",
66
"authors": [
77
"ghillairet <g.hillairet@gmail.com>"
@@ -20,6 +20,6 @@
2020
"tests"
2121
],
2222
"dependencies": {
23-
"underscore": "~1.5.2"
23+
"underscore": "~1.7.0"
2424
}
2525
}

dist/ecore.js

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
(function() {
88

9+
"use strict";
10+
911
// The root object, `window` in the browser, or `global` on the server.
1012
var root = this;
1113

@@ -476,17 +478,36 @@ Ecore.EObjectPrototype = {
476478
eContents: function() {
477479
if (!this.eClass) return [];
478480

479-
var eAllFeatures = this.eClass.get('eAllStructuralFeatures'),
480-
eContainments = _.filter(eAllFeatures, function(feature) {
481+
if (_.isUndefined(this.__updateContents)) {
482+
this.__updateContents = true;
483+
484+
var resource = this.eResource();
485+
if (resource) {
486+
var me = this;
487+
resource.on('add remove', function() {
488+
me.__updateContents = true;
489+
})
490+
}
491+
}
492+
493+
if (this.__updateContents) {
494+
var eAllFeatures = this.eClass.get('eAllStructuralFeatures');
495+
var eContainments = _.filter(eAllFeatures, function(feature) {
481496
return feature.isTypeOf('EReference') &&
482497
feature.get('containment') &&
483498
this.isSet(feature.get('name'));
484499
}, this);
485500

486-
return _.flatten(_.map(eContainments, function(c) {
487-
var value = this.get(c.get('name'));
488-
return value instanceof Ecore.EList ? value.array() : value;
489-
}, this));
501+
var value = null;
502+
this.__eContents = _.flatten(_.map(eContainments, function(c) {
503+
value = this.get(c.get('name'));
504+
return value ? (value.array ? value.array() : value) : [];
505+
}, this));
506+
507+
this.__updateContents = false;
508+
}
509+
510+
return this.__eContents;
490511
},
491512

492513
// Returns the URI of the EObject.
@@ -1894,11 +1915,7 @@ var EClassResource = Ecore.Resource = Ecore.EClass.create({
18941915
_: function(fragment) {
18951916
if (!fragment) return null;
18961917

1897-
if (this.__index == null) {
1898-
this.__index = buildIndex(this);
1899-
}
1900-
1901-
return this.__index[fragment];
1918+
return this._index()[fragment];
19021919
}
19031920
},
19041921
{
@@ -1992,7 +2009,20 @@ var EClassResource = Ecore.Resource = Ecore.EClass.create({
19922009
name: '_index',
19932010
eType: JSObject,
19942011
_: function() {
1995-
return buildIndex(this);
2012+
if (_.isUndefined(this.__updateIndex)) {
2013+
var res = this;
2014+
res.__updateIndex = true;
2015+
res.on('add remove', function() {
2016+
res.__updateIndex = true;
2017+
})
2018+
}
2019+
2020+
if (this.__updateIndex) {
2021+
this.__index = buildIndex(this);
2022+
this.__updateIndex = false;
2023+
}
2024+
2025+
return this.__index;
19962026
}
19972027
}
19982028
]
@@ -2499,5 +2529,5 @@ Ecore.Edit = {
24992529
}
25002530

25012531

2502-
})();
2532+
}.call(this));
25032533

dist/ecore.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ecore.xmi.js

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
(function() {
88

9+
"use strict";
10+
911
// The root object, `window` in the browser, or `global` on the server.
1012
var root = this;
1113

@@ -476,17 +478,36 @@ Ecore.EObjectPrototype = {
476478
eContents: function() {
477479
if (!this.eClass) return [];
478480

479-
var eAllFeatures = this.eClass.get('eAllStructuralFeatures'),
480-
eContainments = _.filter(eAllFeatures, function(feature) {
481+
if (_.isUndefined(this.__updateContents)) {
482+
this.__updateContents = true;
483+
484+
var resource = this.eResource();
485+
if (resource) {
486+
var me = this;
487+
resource.on('add remove', function() {
488+
me.__updateContents = true;
489+
})
490+
}
491+
}
492+
493+
if (this.__updateContents) {
494+
var eAllFeatures = this.eClass.get('eAllStructuralFeatures');
495+
var eContainments = _.filter(eAllFeatures, function(feature) {
481496
return feature.isTypeOf('EReference') &&
482497
feature.get('containment') &&
483498
this.isSet(feature.get('name'));
484499
}, this);
485500

486-
return _.flatten(_.map(eContainments, function(c) {
487-
var value = this.get(c.get('name'));
488-
return value instanceof Ecore.EList ? value.array() : value;
489-
}, this));
501+
var value = null;
502+
this.__eContents = _.flatten(_.map(eContainments, function(c) {
503+
value = this.get(c.get('name'));
504+
return value ? (value.array ? value.array() : value) : [];
505+
}, this));
506+
507+
this.__updateContents = false;
508+
}
509+
510+
return this.__eContents;
490511
},
491512

492513
// Returns the URI of the EObject.
@@ -1894,11 +1915,7 @@ var EClassResource = Ecore.Resource = Ecore.EClass.create({
18941915
_: function(fragment) {
18951916
if (!fragment) return null;
18961917

1897-
if (this.__index == null) {
1898-
this.__index = buildIndex(this);
1899-
}
1900-
1901-
return this.__index[fragment];
1918+
return this._index()[fragment];
19021919
}
19031920
},
19041921
{
@@ -1992,7 +2009,20 @@ var EClassResource = Ecore.Resource = Ecore.EClass.create({
19922009
name: '_index',
19932010
eType: JSObject,
19942011
_: function() {
1995-
return buildIndex(this);
2012+
if (_.isUndefined(this.__updateIndex)) {
2013+
var res = this;
2014+
res.__updateIndex = true;
2015+
res.on('add remove', function() {
2016+
res.__updateIndex = true;
2017+
})
2018+
}
2019+
2020+
if (this.__updateIndex) {
2021+
this.__index = buildIndex(this);
2022+
this.__updateIndex = false;
2023+
}
2024+
2025+
return this.__index;
19962026
}
19972027
}
19982028
]
@@ -2864,5 +2894,5 @@ function formatXml(xml) {
28642894
}
28652895

28662896

2867-
})();
2897+
}.call(this));
28682898

dist/ecore.xmi.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ecore",
33
"description": "Ecore (EMOF) JavaScript Implementation",
4-
"version": "0.4.5",
4+
"version": "0.4.6",
55
"author": "Guillaume Hillairet <g.hillairet@gmail.com>",
66
"repository": {
77
"type": "git",

0 commit comments

Comments
 (0)