Commit 021266d1 authored by Nicolas Biri's avatar Nicolas Biri
Browse files

Add referenceResolution for references with any type

parent b734b88d
v0.6:
- Migration to jsmf-core 0.4
# Changelog
## v0.4
- Introduce helpers
- Introduce "this.assign" for references resolution.
- API refactoring.
v0.6:
- Migration to jsmf-core 0.4
v0.6:
- Migration to jsmf-core 0.4
......@@ -121,7 +121,7 @@ function runResolution(resolution, generated) {
function(elem) {
var values = generated.valuesFor(elem) || [];
_.each(values, function(target) {
if (hasClass(target, relationType)) {
if (relationType === undefined || hasClass(target, relationType)) {
resolution.source[referenceFunctionName](target);
}
});
......
'use strict';
var should = require('should');
var JSMF = require('jsmf-core');
var JSTL = require('../index');
var _ = require('lodash');
describe('References resolution', function() {
it('accept any jsmf object for references with any type', function(done) {
var Foo = new JSMF.Class('Foo', [], {}, {foo: {target: JSMF.JSMFAny}});
var BarSource = new JSMF.Class('BarSource', [], {x: Number});
var BarTarget = new JSMF.Class('BarTarget', [], {y: Number});
var trans = new JSTL.Transformation();
trans.addRule({
in: function(m) {return m.modellingElements.Foo;},
out: function(e) {
var res = new Foo();
this.assign(res, 'foo', e.foo);
return [res];
}
});
trans.addRule({
in: function(m) {return m.modellingElements.BarSource;},
out: function(e) {
var res = new BarTarget({y: e.x});
return [res];
}
});
var f = new Foo({foo: [new BarSource({x: 42})]});
var src = new JSMF.Model('src', {}, [f], true);
var target = new JSMF.Model('target');
trans.apply(src, target);
target.modellingElements.BarTarget.should.not.be.empty();
target.modellingElements.Foo[0].foo.should.have.length(1);
done();
});
});
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