Expose Internal Methods and Properties
See original GitHub issueI’ve hit an issue where I need to programmatically control other Autocomplete instances on the same page, but (at least from my understanding) this is impossible.
Having an initiation function like this, is great:
autocomplete({
element: document.querySelector( '' ),
source: [ 'option', 'option-1', 'options-2']
})
But there is no way to reference this input after it initiates. How hard would it be to have this return the input instance? i.e.
const input = autocomplete({
element: document.querySelector( '' ),
source: [ 'option', 'option-1', 'options-2']
})
// Later
input.hide();
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Expose public properties of internal types - MSDN - Microsoft
Is it possible to expose one public class like this that exposes an instance of some internal classes? namespace MyNamespace
Read more >Access to internal classes from another project - Stack Overflow
In Settings class I store internal variables (and methods) for app which cannot be visible from other projects. But those settings need to...
Read more >Private and protected properties and methods
Internal interface – methods and properties, accessible from other methods of the class, but not from the outside.
Read more >Hiding internal framework methods and properties from web ...
In hindsight, exposing framework internals that way (even prefixed with an underscore, etc.) seems like a bad idea:
Read more >How to unit test Internal classes in .NET Core applications?
The creation of unit tests is an important step in ensuring the quality of a project. In general, most public methods are tested,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@JakeChampion this change to the
accessibleAutocomplete
function returns the component instance.Another good use-case I have come across for returning the component from the wrapper module:
https://github.com/alphagov/accessible-autocomplete/blob/935f0d43aea1c606e6b38985e3fe7049ddbe98be/src/wrapper.js#L4
We wanted to implement a button to clear and re-focus the input field, this currently has a sub-optimal user-experience because it requires aligning to some timers internal to accessible-autocomplete. If we reset the input and then re-focus the input before the internal timer has fired, then the input’s value reverts to what it was before being reset. Those timers are there to integrate with Dragon NaturallySpeaking – https://github.com/alphagov/accessible-autocomplete/blob/935f0d43aea1c606e6b38985e3fe7049ddbe98be/src/autocomplete.js#L107-L125
If the component was returned, we would be able to call
component.getDirectInputChanges()
to update the internal state of the component and then immediately focus on the input, and have it work correctly.This is the code we have to have right now to reset and re-focus the input:
If we had access to the component instance, we could refactor the above into: