diff --git a/package.json b/package.json index ef744fa..21ff28e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "functional-models", - "version": "1.0.11", + "version": "1.0.13", "description": "A library for creating JavaScript function based models.", "main": "index.js", "scripts": { diff --git a/src/models.js b/src/models.js index 7f8adca..20e2cbc 100644 --- a/src/models.js +++ b/src/models.js @@ -43,6 +43,12 @@ const Model = ( ) const create = (instanceValues = {}) => { + const specialInstanceProperties1 = MODEL_DEF_KEYS.reduce((acc, key) => { + if (key in instanceValues) { + return {...acc, [key]: instanceValues[key]} + } + return acc + }, {}) const loadedInternals = instanceProperties.reduce( (acc, [key, property]) => { const propertyGetter = property.createGetter(instanceValues[key]) @@ -75,7 +81,8 @@ const Model = ( {}, loadedInternals, specialProperties, - frameworkProperties + frameworkProperties, + specialInstanceProperties1, ) if (instanceCreatedCallback) { instanceCreatedCallback(instance) diff --git a/test/src/models.test.js b/test/src/models.test.js index f78e164..ec58487 100644 --- a/test/src/models.test.js +++ b/test/src/models.test.js @@ -39,6 +39,16 @@ describe('/src/models.js', () => { const actual = instance.meta.getModel().getProperties().myProperty assert.isOk(actual) }) + it('should combine the meta within the instance values', () => { + const input = { + myProperty: Property({ required: true }), + } + const model = Model('name', input) + const instance = model.create({ myProperty: 'value', meta: {random: () => 'random'}}) + const actual = instance.meta.random() + const expected = 'random' + assert.equal(actual, expected) + }) it('should flow through the additional special functions within the keyValues', () => { const input = { myProperty: Property({ required: true }), diff --git a/test/src/properties.test.js b/test/src/properties.test.js index 1d39d8d..dfbce26 100644 --- a/test/src/properties.test.js +++ b/test/src/properties.test.js @@ -508,7 +508,7 @@ describe('/src/properties.js', () => { const input = ['obj-id'] const fetcher = sinon .stub() - .callsFake((modelName, instanceValues) => instanceValues) + .callsFake((modelName, id) => ({id})) await ReferenceProperty(TestModel1, { fetcher, }).createGetter(...input)()