Browse Source

refactor: change data var to defaultValue

feature/data-sources
danstarns 2 years ago
parent
commit
c0c79dd61f
  1. 10
      docs/modules/DataSources.md
  2. 6
      src/data_sources/model/ComponentDataVariable.ts
  3. 6
      src/data_sources/model/DataVariable.ts
  4. 6
      src/data_sources/model/TraitDataVariable.ts
  5. 4
      src/data_sources/view/ComponentDataVariableView.ts
  6. 6
      test/specs/data_sources/__snapshots__/serialization.ts.snap
  7. 16
      test/specs/data_sources/model/ComponentDataVariable.ts
  8. 8
      test/specs/data_sources/model/StyleDataVariable.ts
  9. 16
      test/specs/data_sources/model/TraitDataVariable.ts
  10. 12
      test/specs/data_sources/serialization.ts
  11. 8
      test/specs/data_sources/transformers.ts

10
docs/modules/DataSources.md

@ -52,7 +52,7 @@ editor.addComponents([
components: [
{
type: 'data-variable',
value: 'default',
defaultValue: 'default',
path: 'my-datasource.id1.content',
},
],
@ -76,14 +76,14 @@ editor.addComponents([
components: [
{
type: 'data-variable',
value: 'default',
defaultValue: 'default',
path: 'my-datasource.id1.content',
},
],
style: {
color: {
type: 'data-variable',
value: 'red',
defaultValue: 'red',
path: 'my-datasource.id2.color',
},
},
@ -118,7 +118,7 @@ editor.addComponents([
name: 'value',
value: {
type: 'data-variable',
value: 'default',
defaultValue: 'default',
path: 'my-datasource.id1.value',
},
},
@ -253,7 +253,7 @@ editor.addComponents([
components: [
{
type: 'data-variable',
value: 'default',
defaultValue: 'default',
path: 'my-datasource.id1.counter',
},
],

6
src/data_sources/model/ComponentDataVariable.ts

@ -10,13 +10,13 @@ export default class ComponentDataVariable extends Component {
...super.defaults,
type: DataVariableType,
path: '',
value: '',
defaultValue: '',
};
}
getInnerHTML(opts: ToHTMLOptions) {
const { path, value } = this.attributes;
const val = this.em.DataSources.getValue(path, value);
const { path, defaultValue } = this.attributes;
const val = this.em.DataSources.getValue(path, defaultValue);
return val;
}

6
src/data_sources/model/DataVariable.ts

@ -10,7 +10,7 @@ export default class DataVariable extends Model {
defaults() {
return {
type: DataVariableType,
value: '',
defaultValue: '',
path: '',
};
}
@ -36,8 +36,8 @@ export default class DataVariable extends Model {
}
getDataValue() {
const { path, value } = this.attributes;
const val = this.em?.DataSources?.getValue?.(path, value);
const { path, defaultValue } = this.attributes;
const val = this.em?.DataSources?.getValue?.(path, defaultValue);
return val;
}

6
src/data_sources/model/TraitDataVariable.ts

@ -4,11 +4,9 @@ import Trait from '../../trait_manager/model/Trait';
export default class TraitDataVariable extends DataVariable {
trait?: Trait;
initialize(attrs: any, options: any) {
super.initialize(attrs, options);
constructor(attrs: any, options: any) {
super(attrs, options);
this.trait = options.trait;
return this;
}
onDataSourceChange() {

4
src/data_sources/view/ComponentDataVariableView.ts

@ -37,8 +37,8 @@ export default class ComponentDataVariableView extends ComponentView<ComponentDa
postRender() {
const { model, el, em } = this;
const { path, value } = model.attributes;
el.innerHTML = em.DataSources.getValue(path, value);
const { path, defaultValue } = model.attributes;
el.innerHTML = em.DataSources.getValue(path, defaultValue);
super.postRender();
}
}

6
test/specs/data_sources/__snapshots__/serialization.ts.snap

@ -12,9 +12,9 @@ exports[`DataSource Serialization .getProjectData ComponentDataVariable 1`] = `
{
"components": [
{
"defaultValue": "default",
"path": "component-serialization.id1.content",
"type": "data-variable",
"value": "default",
},
],
"tagName": "h1",
@ -99,9 +99,9 @@ exports[`DataSource Serialization .getProjectData StyleDataVariable 1`] = `
],
"style": {
"color": {
"defaultValue": "black",
"path": "colors-data.id1.color",
"type": "data-variable",
"value": "black",
},
},
},
@ -125,9 +125,9 @@ exports[`DataSource Serialization .getProjectData TraitDataVariable 1`] = `
},
"attributes-data-variable": {
"value": {
"defaultValue": "default",
"path": "test-input.id1.value",
"type": "data-variable",
"value": "default",
},
},
"tagName": "input",

16
test/specs/data_sources/model/ComponentDataVariable.ts

@ -47,7 +47,7 @@ describe('ComponentDataVariable', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'ds1.id1.name',
},
],
@ -69,7 +69,7 @@ describe('ComponentDataVariable', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'ds2.id1.name',
},
],
@ -90,7 +90,7 @@ describe('ComponentDataVariable', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'unknown.id1.name',
},
],
@ -112,7 +112,7 @@ describe('ComponentDataVariable', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'ds3.id1.name',
},
],
@ -137,7 +137,7 @@ describe('ComponentDataVariable', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: `${dataSource.id}.id1.name`,
},
],
@ -164,7 +164,7 @@ describe('ComponentDataVariable', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'ds4.id1.name',
},
],
@ -198,7 +198,7 @@ describe('ComponentDataVariable', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'dsNestedObject.id1.nestedObject.name',
},
],
@ -237,7 +237,7 @@ describe('ComponentDataVariable', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'dsNestedArray.id1.items.0.nestedObject.name',
},
],

8
test/specs/data_sources/model/StyleDataVariable.ts

@ -48,7 +48,7 @@ describe('StyleDataVariable', () => {
style: {
color: {
type: DataVariableType,
value: 'black',
defaultValue: 'black',
path: 'colors-data.id1.color',
},
},
@ -72,7 +72,7 @@ describe('StyleDataVariable', () => {
style: {
color: {
type: DataVariableType,
value: 'black',
defaultValue: 'black',
path: 'colors-data.id1.color',
},
},
@ -96,7 +96,7 @@ describe('StyleDataVariable', () => {
style: {
color: {
type: DataVariableType,
value: 'black',
defaultValue: 'black',
path: 'unknown.id1.color',
},
},
@ -127,7 +127,7 @@ describe('StyleDataVariable', () => {
style: {
color: {
type: DataVariableType,
value: 'black',
defaultValue: 'black',
path: 'style-data.id1.nestedObject.color',
},
},

16
test/specs/data_sources/model/TraitDataVariable.ts

@ -52,7 +52,7 @@ describe('TraitDataVariable', () => {
name: 'value',
value: {
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: `${inputDataSource.id}.id1.value`,
},
},
@ -81,7 +81,7 @@ describe('TraitDataVariable', () => {
name: 'placeholder',
value: {
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: `${inputDataSource.id}.id1.value`,
},
},
@ -117,7 +117,7 @@ describe('TraitDataVariable', () => {
name: 'value',
value: {
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: `${inputDataSource.id}.id1.value`,
},
},
@ -159,7 +159,7 @@ describe('TraitDataVariable', () => {
name: 'value',
value: {
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'nested-input-data.id1.nestedObject.value',
},
},
@ -191,7 +191,7 @@ describe('TraitDataVariable', () => {
name: 'checked',
value: {
type: 'data-variable',
value: 'false',
defaultValue: 'false',
path: `${inputDataSource.id}.id1.value`,
},
valueTrue: 'true',
@ -233,7 +233,7 @@ describe('TraitDataVariable', () => {
name: 'src',
value: {
type: 'data-variable',
value: 'default',
defaultValue: 'default',
path: `${inputDataSource.id}.id1.value`,
},
},
@ -269,7 +269,7 @@ describe('TraitDataVariable', () => {
name: 'href',
value: {
type: 'data-variable',
value: 'default',
defaultValue: 'default',
path: `${inputDataSource.id}.id1.value`,
},
},
@ -306,7 +306,7 @@ describe('TraitDataVariable', () => {
changeProp: true,
value: {
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: `${inputDataSource.id}.id1.value`,
},
},

12
test/specs/data_sources/serialization.ts

@ -96,7 +96,7 @@ describe('DataSource Serialization', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: `${componentDataSource.id}.id1.content`,
},
],
@ -113,7 +113,7 @@ describe('DataSource Serialization', () => {
test('ComponentDataVariable', () => {
const dataVariable = {
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: `${componentDataSource.id}.id1.content`,
};
@ -136,7 +136,7 @@ describe('DataSource Serialization', () => {
test('StyleDataVariable', () => {
const dataVariable = {
type: DataVariableType,
value: 'black',
defaultValue: 'black',
path: 'colors-data.id1.color',
};
@ -168,7 +168,7 @@ describe('DataSource Serialization', () => {
test('TraitDataVariable', () => {
const dataVariable = {
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: `${traitDataSource.id}.id1.value`,
};
@ -309,7 +309,7 @@ describe('DataSource Serialization', () => {
color: {
path: 'colors-data.id1.color',
type: 'data-variable',
value: 'black',
defaultValue: 'black',
},
},
},
@ -345,7 +345,7 @@ describe('DataSource Serialization', () => {
value: {
path: 'test-input.id1.value',
type: 'data-variable',
value: 'default',
defaultValue: 'default',
},
},
tagName: 'input',

8
test/specs/data_sources/transformers.ts

@ -53,7 +53,7 @@ describe('DataSource Transformers', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'test-data-source.id1.content',
},
],
@ -95,7 +95,7 @@ describe('DataSource Transformers', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'test-data-source.id1.content',
},
],
@ -135,7 +135,7 @@ describe('DataSource Transformers', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'test-data-source.id1.content',
},
],
@ -171,7 +171,7 @@ describe('DataSource Transformers', () => {
components: [
{
type: DataVariableType,
value: 'default',
defaultValue: 'default',
path: 'test-data-source.id1.content',
},
],

Loading…
Cancel
Save