-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
skip/disable/remove fetch config conditionally #215
Comments
What do you mean by "remains injected into the component"? If I'm understanding correctly, isn't that what you'd want; otherwise, there would be nothing for the component to render.
Probably the easiest thing to do would be to set |
I'd like no NOT receive that prop when I make the text input empty again, because otherwise my autocomplete dropdown keeps showing former results when the input is empty. It looks to me the lib should do state cleanup when it detects that a fetch config has just been removed. I'd like to never receive the As expected, the following does not really do what I want: const ConnectedCompanyField = connect(({ value }) => {
return {
fieldValuesFetch: {
comparison: value.length > 2 && value,
value: () => searchField(value, ProviderLabel),
},
};
})(CompanyField); With this config the |
Here is a basic code solution to add the behavior I want. I'd like to submit a proper PR if you agree with this behavior and the implementation: const arrayDiff = function(a,b) {
return a.filter(function(i) {
return b.indexOf(i) < 0;
});
};
const omitKeys = function omitKeys(obj,keys) {
const { x, ...copy } = obj;
keys.forEach(key => delete copy[key]);
return copy
} refetchDataFromMappings(mappings) {
mappings = coerceMappings(mappings)
Object.keys(mappings).forEach(prop => {
/// ... nothing here, keep the original code
})
// Do state cleanup on mapping removal
const removedMappingProps = arrayDiff(Object.keys(this.state.mappings),Object.keys(mappings));
// clear refresh timeouts before removal
if ( removedMappingProps.length ) {
removedMappingProps.forEach(prop => {
if (this.state.refreshTimeouts[prop]) {
window.clearTimeout(this.state.refreshTimeouts[prop]);
}
})
// remove prop mapping from state
this.setState({
mappings: omitKeys(this.state.mappings,removedMappingProps),
data: omitKeys(this.state.data,removedMappingProps),
startedAts: omitKeys(this.state.startedAts,removedMappingProps),
refreshTimeouts: omitKeys(this.state.refreshTimeouts,removedMappingProps),
});
}
} |
Alternatively, could you just control this with a conditional
I'd rather not change the internals of the library for this since. Perhaps we could have some utility to help make this easier, but I don't think previously set state should "automagically" be cleared. |
Hi,
What I want to do is pretty simple and I thought it would be supported but I can't find such an option so far.
I have an input text on which I'd like to provide autocomplete. But I don't want to trigger requests unless the text size is > 2.
I've tried the following:
Even if the
fieldValuesFetch
is not returned when text is small, the formerfieldValuesFetch
remains injected into the component. It looks like a bug to me, but maybe it's intended?I think it would be easier to provide an ability to "skip" / "ignore" a fetch conditionnally.
Apollo provides an API similar to this:
The text was updated successfully, but these errors were encountered: