laravel-jetstream
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -13,2 +13,4 @@ 'use strict'; | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -26,4 +28,17 @@ | ||
this.recentlySuccessful = false; | ||
this.isDirty = false; | ||
this.withData(data).withOptions(options); | ||
return new Proxy(this, { | ||
set: function set(obj, prop, value) { | ||
obj[prop] = value; | ||
if (_util.reservedFieldNames.indexOf(prop) === -1 && value !== obj.initial[prop]) { | ||
obj.isDirty = true; | ||
} | ||
return true; | ||
} | ||
}); | ||
} | ||
@@ -52,2 +67,4 @@ | ||
this.isDirty = false; | ||
return this; | ||
@@ -60,3 +77,4 @@ } | ||
bag: 'default', | ||
resetOnSuccess: true | ||
resetOnSuccess: true, | ||
setInitialOnSuccess: false | ||
}; | ||
@@ -72,2 +90,6 @@ | ||
if (options.hasOwnProperty('setInitialOnSuccess')) { | ||
this.__options.setInitialOnSuccess = options.setInitialOnSuccess; | ||
} | ||
return this; | ||
@@ -106,2 +128,4 @@ } | ||
(0, _util.merge)(this, this.initial); | ||
this.isDirty = false; | ||
} | ||
@@ -219,2 +243,9 @@ }, { | ||
this.reset(); | ||
} else if (this.__options.setInitialOnSuccess) { | ||
var _data = this.data(), | ||
_error_bag = _data._error_bag, | ||
data = _objectWithoutProperties(_data, ['_error_bag']); | ||
this.setInitialValues(data); | ||
this.isDirty = false; | ||
} | ||
@@ -221,0 +252,0 @@ } |
@@ -7,3 +7,3 @@ 'use strict'; | ||
exports.guardAgainstReservedFieldName = guardAgainstReservedFieldName; | ||
var reservedFieldNames = exports.reservedFieldNames = ['__options', '__inertia', '__page', '__validateRequestType', 'data', 'delete', 'errorFor', 'errorsFor', 'hasErrors', 'initial', 'onFail', 'onSuccess', 'patch', 'post', 'processing', 'put', 'reset', 'submit', 'successful', 'withData', 'withOptions']; | ||
var reservedFieldNames = exports.reservedFieldNames = ['__options', '__inertia', '__page', '__validateRequestType', 'data', 'delete', 'errorFor', 'errorsFor', 'hasErrors', 'initial', 'isDirty', 'onFail', 'onSuccess', 'patch', 'post', 'processing', 'put', 'recentlySuccessful', 'reset', 'submit', 'successful', 'withData', 'withOptions']; | ||
@@ -10,0 +10,0 @@ function guardAgainstReservedFieldName(fieldName) { |
{ | ||
"name": "laravel-jetstream", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -1,2 +0,9 @@ | ||
import { guardAgainstReservedFieldName, isArray, isFile, merge, objectToFormData } from './util'; | ||
import { | ||
guardAgainstReservedFieldName, | ||
isArray, | ||
isFile, | ||
merge, | ||
objectToFormData, | ||
reservedFieldNames | ||
} from './util'; | ||
@@ -8,5 +15,18 @@ class InertiaForm { | ||
this.recentlySuccessful = false; | ||
this.isDirty = false; | ||
this.withData(data) | ||
.withOptions(options) | ||
return new Proxy(this, { | ||
set(obj, prop, value) { | ||
obj[prop] = value; | ||
if ((reservedFieldNames.indexOf(prop) === -1) && value !== obj.initial[prop]) { | ||
obj.isDirty = true; | ||
} | ||
return true; | ||
} | ||
}) | ||
} | ||
@@ -37,2 +57,4 @@ | ||
this.isDirty = false; | ||
return this; | ||
@@ -45,2 +67,3 @@ } | ||
resetOnSuccess: true, | ||
setInitialOnSuccess: false, | ||
}; | ||
@@ -56,2 +79,6 @@ | ||
if (options.hasOwnProperty('setInitialOnSuccess')) { | ||
this.__options.setInitialOnSuccess = options.setInitialOnSuccess; | ||
} | ||
return this; | ||
@@ -86,2 +113,4 @@ } | ||
merge(this, this.initial); | ||
this.isDirty = false; | ||
} | ||
@@ -180,2 +209,6 @@ | ||
this.reset(); | ||
} else if (this.__options.setInitialOnSuccess) { | ||
const { _error_bag, ...data } = this.data(); | ||
this.setInitialValues(data); | ||
this.isDirty = false; | ||
} | ||
@@ -182,0 +215,0 @@ } |
@@ -12,2 +12,3 @@ export const reservedFieldNames = [ | ||
'initial', | ||
'isDirty', | ||
'onFail', | ||
@@ -19,2 +20,3 @@ 'onSuccess', | ||
'put', | ||
'recentlySuccessful', | ||
'reset', | ||
@@ -21,0 +23,0 @@ 'submit', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37702
29
719
32