Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 8 additions & 1 deletion src/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -75,7 +81,8 @@ const Model = (
{},
loadedInternals,
specialProperties,
frameworkProperties
frameworkProperties,
specialInstanceProperties1,
)
if (instanceCreatedCallback) {
instanceCreatedCallback(instance)
Expand Down
10 changes: 10 additions & 0 deletions test/src/models.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
2 changes: 1 addition & 1 deletion test/src/properties.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)()
Expand Down