Skip to content

Commit

Permalink
revert: revert #542
Browse files Browse the repository at this point in the history
  • Loading branch information
foxhound87 committed Oct 1, 2020
1 parent 17ccdfc commit c5c427e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 55 deletions.
23 changes: 11 additions & 12 deletions src/shared/Initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@ export default {
_.forIn(fields, (field, key) => {
const path = $path(key);
const $f = this.select(path, null, false);

if (_.isNil($f)) {
if (fallback) {
this.initField(key, path, field, update);
return;
}
else {
const structPath = utils.pathToStruct(path);
const struct = this.state.struct();
const found = struct.filter(s => s.startsWith(structPath))
.find(s => s.charAt(structPath.length) === '.'
|| s.substr(structPath.length, 2) === '[]'
|| s === structPath)

const structPath = utils.pathToStruct(path);
const struct = this.state.struct();
const found = struct.filter(s => s.startsWith(structPath))
.find(s => s.charAt(structPath.length) === '.'
|| s.substr(structPath.length, 2) === '[]'
|| s === structPath)

if (found)
this.initField(key, path, field, update);
if (found)
this.initField(key, path, field, update);
}
}
})
},
Expand All @@ -45,7 +44,7 @@ export default {
const initial = this.state.get('current', 'props');
const struct = utils.pathToStruct(path);
// try to get props from separated objects
const $try = prop => initial[prop] && initial[prop][struct];
const $try = prop => _.get(initial[prop], struct);

const props = {
$value: _.get(initial['values'], path),
Expand Down
59 changes: 16 additions & 43 deletions tests/fixes.values.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('$481 Field values checks', () => {
});

describe('separated has correct definition', () => {
it('', () => {
it('', () => {
expect($.$492.$('club.name').value).to.be.equal('')
expect($.$492.$('club.city').value).to.be.equal('')
expect($.$492.values())
Expand All @@ -292,7 +292,7 @@ describe('separated has correct definition', () => {
});

describe('set null value', () => {
it('', () => {
it('', () => {
expect($.$495.$('club.name').value).to.be.equal('JJSC')
expect($.$495.$('club.city').value).to.be.equal('Taipei')
$.$495.$('club').set(null)
Expand All @@ -307,7 +307,7 @@ describe('set null value', () => {
});

describe('falsy fallback', () => {
it('', () => {
it('', () => {
expect($.$505.$('club.name').value).to.be.equal('JJSC')
expect($.$505.$('club.city').value).to.be.equal('Taipei')
expect($.$505.$('club').has('area')).to.be.equal(false)
Expand All @@ -316,21 +316,21 @@ describe('falsy fallback', () => {
});

describe('null date', () => {
it('', () => {
it('', () => {
expect($.$507.$('people.0.birthday').value).to.be.equal(null)
expect($.$507.$('people').add().$('birthday').value).to.be.equal(null)
})
});

describe('update with input', () => {
it('', () => {
it('', () => {
expect($.$514.$('priority').value).to.be.equal(1)
expect($.$514.$('itineraryItems.0.hotel.starRating').value).to.be.equal(5)
})
});

describe('new form with nested array values', () => {
it('', () => {
it('', () => {
const fields = [
'purpose',
'trip.itineraryItems[].hotel.name',
Expand Down Expand Up @@ -363,7 +363,7 @@ describe('new form with nested array values', () => {
});

describe('update to nested array items', () => {
it('', () => {
it('', () => {
const fields = [
'bulletin',
'bulletin.jobs',
Expand Down Expand Up @@ -417,15 +417,15 @@ describe('#523', () => {
name: "nestedB",
label: "nestedB"
}]
}];
}];
const $523 = new Form({fields}, {name: 'Form 523'})
expect($523.isDirty).to.be.false
})
});

describe('update nested nested array items', () => {
it('', () => {
it('', () => {
const fields = [
'pricing',
'pricing.value[]',
Expand All @@ -448,7 +448,7 @@ describe('update nested nested array items', () => {
};
const $526 = new Form({fields, values}, {name: 'Form 526'})
console.debug('pricing.value.0.initial', $526.$('pricing.value.0').initial)
console.debug('pricing.value.0.prices.initial', $526.$('pricing.value.0.prices').initial)
console.debug('pricing.value.0.prices.initial', $526.$('pricing.value.0.prices').initial)
$526.update({
pricing: {
value: [
Expand Down Expand Up @@ -476,7 +476,7 @@ describe('update nested nested array items', () => {
});

describe('falsy fallback for array items', () => {
it('', () => {
it('', () => {
const fields = [
'purpose',
'trip.itineraryItems[].hotel.name',
Expand All @@ -489,16 +489,16 @@ describe('falsy fallback for array items', () => {
itineraryItems: [{
hotel: {
name: 'Shangri-La Hotel',
starRating: '5.0',
favorite: true
starRating: '5.0',
favorite: true
},
}, {
hotel: null,
}, {
hotel: {
name: 'Trump Hotel',
starRating: '5.0',
favorite: false
starRating: '5.0',
favorite: false
},
}]
}
Expand All @@ -511,30 +511,3 @@ describe('falsy fallback for array items', () => {
expect($527.select('trip.itineraryItems.0.hotel.favorite', null, false)).to.be.undefined
})
});

describe('output goes wrong', () => {
it.only('', () => {
const fields = [
'customer',
'customer.name',
'customerid'
];
const labels = {
'customer': 'Customer',
'customer.name': 'name',
};
const output = {
customer: c => c ? c.id : c
};
const values = {
customer: {
id: 'c-001',
name: 'Allen'
}
}

const $541 = new Form({fields, labels, output, values}, {name: 'Form 541', options:{fallback: false}});
expect(typeof $541.$('customer.name').$output).to.be.equal('function')
$541.values();
})
});

0 comments on commit c5c427e

Please sign in to comment.