Skip to content

Debounced SDK methods lose this context #99

@gaelsimon

Description

@gaelsimon

Description

Debounced SDK methods lose this context, causing runtime errors when the SDK tries to access instance properties.

Steps to Reproduce

const debounced = debouncePromise(localitiesService.search, 100);
debounced(request); // TypeError: undefined is not an object (evaluating 'this.sessionId')

Proposed Fix

Wrap in arrow function to preserve context:

this.debouncedLocalitiesSearch = debouncePromise(
  (request) => localitiesService.search(request), 
  100
);

Or update debouncePromise to use fn.apply(this, args) instead of fn(...args).
Or bind the method like.

const debounced = debouncePromise(localitiesService.search.bind(localitiesService), 100);
debounced(request).then(...);

Map JS Doc need to be updated too

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions