Commit 190cb9f4 authored by Nicolas Biri's avatar Nicolas Biri

Add refreshModel aside refreshElement

parent 7c1d9ce6
Pipeline #851 passed with stage
in 44 seconds
......@@ -375,24 +375,24 @@ function prefixedName(pre, n) {
return pre + _.upperFirst(n)
}
function refresh(o) {
function refreshElement(o) {
const mm = o.conformsTo()
if (!mm) {return o}
const oBackup = Object.assign({}, o)
for (let x in o) {delete o[x]}
createAttributes(o, mm)
createReferences(o, mm)
for (let x in oBackup) {
o[x] = oBackup[x]
}
_.forEach(oBackup, (v, k) => {
if (v !== undefined) { o[k] = v }
})
return o
}
const onError =
{ 'throw': function(o,n,x) {throw new TypeError(`Invalid assignment: ${x} for property ${n} of object ${o}`)}
, 'log': function(o,n,x) {console.log(`assignment: ${x} for property ${n} of object ${o}`)}
, 'silent': function() {}
}
module.exports = { Class, isJSMFClass, hasClass, onError, refresh }
module.exports = { Class, isJSMFClass, hasClass, onError, refreshElement }
......@@ -32,8 +32,14 @@ let isJSMFElement, conformsTo, generateId
generateId = common.generateId
}).call()
let isJSMFClass, refreshElement
(function() {
const C = require('./Class')
isJSMFClass = C.isJSMFClass
refreshElement = C.refreshElement
}).call()
const isJSMFEnum = require('./Enum').isJSMFEnum
const isJSMFClass = require('./Class').isJSMFClass
function Model(name, referenceModel, modellingElements, transitive) {
this.__name = name
......@@ -153,5 +159,10 @@ function dispatch(elems) {
{})
}
function refreshModel(o) {
if (!(o instanceof Model)) {throw new TypeError('Model expected')}
_.forEach(o.elements(), refreshElement)
}
module.exports = {Model, modelExport}
module.exports = {Model, modelExport, refreshModel}
......@@ -165,7 +165,7 @@ describe('Class Flexibility', () => {
const A = new Class('A', [], {a: Number})
const a = new A({a: 12})
delete A.addAttribute('b', String)
JSMF.refresh(a)
JSMF.refreshElement(a)
function test() {a.b = 42}
test.should.throw()
done()
......@@ -175,7 +175,7 @@ describe('Class Flexibility', () => {
const A = new Class('A', [], {a: Number})
const a = new A({a: 12})
delete A.addAttribute('b', String)
JSMF.refresh(a)
JSMF.refreshElement(a)
function test() {a.b = 42}
test.should.throw()
done()
......@@ -186,7 +186,7 @@ describe('Class Flexibility', () => {
const A = new Class('A', [], {a: Number}, {}, true)
const a = new A({a: 12})
delete A.addAttribute('b', String)
JSMF.refresh(a)
JSMF.refreshElement(a)
function test() {a.b = 42}
test.should.not.throw()
done()
......@@ -197,7 +197,7 @@ describe('Class Flexibility', () => {
const B = new Class('B')
const a = new A({a: 12})
delete A.addReference('b', B)
JSMF.refresh(a)
JSMF.refreshElement(a)
function test() {a.b = new A()}
test.should.not.throw()
function testAddFunction() {a.addB(new A())}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment