Skip to content

Commit 4b12b18

Browse files
committed
fix(model): prevent request config from ditching private data (#185)
Use `Object.defineProperty` to set `_config`. This way we don't need to ditch private data anymore.
1 parent d6943a0 commit 4b12b18

File tree

2 files changed

+2
-10
lines changed

2 files changed

+2
-10
lines changed

Diff for: src/Model.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export default class Model extends StaticModel {
3838
}
3939

4040
config(config) {
41-
this._config = config
41+
Object.defineProperty(this, '_config', { get: () => config })
42+
4243
return this
4344
}
4445

@@ -313,11 +314,6 @@ export default class Model extends StaticModel {
313314

314315
// Check if config has data
315316
if ('data' in _config) {
316-
// Ditch private data
317-
_config.data = Object.fromEntries(
318-
Object.entries(_config.data).filter(([key]) => !key.startsWith('_'))
319-
)
320-
321317
const _hasFiles = Object.keys(_config.data).some((property) => {
322318
if (Array.isArray(_config.data[property])) {
323319
return _config.data[property].some((value) => value instanceof File)

Diff for: tests/model.test.js

-4
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ describe('Model methods', () => {
414414

415415
axiosMock.onAny().reply((config) => {
416416
const _post = post
417-
delete _post._config
418417

419418
expect(config.method).toEqual('patch')
420419
expect(config.data).toEqual(JSON.stringify(_post))
@@ -452,7 +451,6 @@ describe('Model methods', () => {
452451

453452
axiosMock.onAny().reply((config) => {
454453
const _post = post
455-
delete _post._config
456454

457455
expect(config.method).toEqual('post')
458456
expect(config.data).toEqual(JSON.stringify(_post))
@@ -572,7 +570,6 @@ describe('Model methods', () => {
572570
axiosMock.onAny().reply((config) => {
573571
let _data
574572
const _post = post
575-
delete _post._config
576573

577574
if (config.headers['Content-Type'] === 'multipart/form-data') {
578575
_data = Object.fromEntries(config.data)
@@ -634,7 +631,6 @@ describe('Model methods', () => {
634631
axiosMock.onAny().reply((config) => {
635632
let _data
636633
const _post = post
637-
delete _post._config
638634

639635
if (config.headers['Content-Type'] === 'multipart/form-data') {
640636
_data = JSON.stringify(Object.fromEntries(config.data))

0 commit comments

Comments
 (0)