Skip to content

Commit

Permalink
[xprototype#4/feature] Allow configure safe mode to main data transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
wilcorrea committed Mar 29, 2019
1 parent c8a65e3 commit 2d6f126
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
21 changes: 20 additions & 1 deletion src/app/Prototype/Base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-underscore-dangle */
import components from 'src/config/app/components'
import { apply } from 'src/app/Util'
import { apply, clone } from 'src/app/Util'
import { lang } from 'src/app/Util/Lang'

/**
* @typedef {Base}
Expand Down Expand Up @@ -161,6 +162,24 @@ export default class Base {
})
}

/**
* @param {String|Array} key
* @param {string} [fallback]
* @returns {String|Object}
*/
$lang (key, fallback = '') {
return lang(key, fallback)
}

/**
* @param {*} element
* @param {Function} action
* @returns {*}
*/
$clone (element, action = (value) => value) {
return clone(element, action)
}

/**
* @param {string} component
* @returns {this}
Expand Down
18 changes: 16 additions & 2 deletions src/app/Prototype/Components/Form/PrototypeFieldComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default {
validations: {
type: Object,
default: () => ({})
},
safe: {
type: Boolean,
default: true
}
},
/**
Expand Down Expand Up @@ -64,6 +68,16 @@ export default {
attrs: { ...field.attrs },
on: { ...field.listeners, input: ($event) => this.componentInput($event, field) }
})
},
/**
* @param {Object} value
*/
updateRecord (value) {
if (this.safe) {
this.record = this.$util.clone(value)
return
}
this.record = value
}
},
/**
Expand All @@ -75,14 +89,14 @@ export default {
value: {
deep: true,
handler (value) {
this.record = this.$util.clone(value)
this.updateRecord(value)
}
}
},
/**
*/
created () {
this.counter = 1
this.record = this.$util.clone(this.value)
this.updateRecord(this.value)
}
}
10 changes: 0 additions & 10 deletions src/app/Prototype/Prototype.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable no-underscore-dangle */
import Skeleton from './Skeleton'
import { lang } from 'src/app/Util/Lang'

import Field from 'src/app/Prototype/Prototype/Field'
import FieldForm from 'src/app/Prototype/Prototype/FieldForm'
Expand All @@ -17,15 +16,6 @@ export default class Prototype extends Skeleton {
*/
static mixins = [Field, FieldForm, FieldIs, FieldTable, Action]

/**
* @param {String|Array} key
* @param {string} [fallback]
* @returns {String|Object}
*/
$lang (key, fallback = '') {
return lang(key, fallback)
}

/**
* @override
*/
Expand Down
26 changes: 21 additions & 5 deletions src/app/Prototype/Skeleton.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Base from 'src/app/Prototype/Base'
import { clone } from 'src/app/Util'

/**
* @typedef {Skeleton}
*/
export default class Skeleton extends Base {
/**
* @type {Boolean}
*/
safe = true

/**
* @param {string} name
* @param {string} label
Expand Down Expand Up @@ -119,28 +123,40 @@ export default class Skeleton extends Base {
* @returns {Object}
*/
hooks () {
return clone(this.__hooks)
if (this.safe) {
return this.clone(this.__hooks)
}
return this.__hooks
}

/**
* @returns {Object}
*/
fields () {
return clone(this.__fields)
if (this.safe) {
return this.clone(this.__fields)
}
return this.__fields
}

/**
* @returns {Object}
*/
sections () {
return clone(this.__sections)
if (this.safe) {
return this.clone(this.__sections)
}
return this.__sections
}

/**
* @returns {Array}
*/
actions () {
return clone(Object.values(this.__actions))
if (this.safe) {
return this.clone(Object.values(this.__actions))
}
return Object.values(this.__actions)
}

/**
Expand Down

0 comments on commit 2d6f126

Please sign in to comment.