Let me know if I'm overcomplicating something. This is what we used to have in 3.6
const isTrailer = info.contentTypeId === ContentType.Trailer.id;
const insert = (item) => iif(isTrailer, insertItem(item), append([item]));
setState(
patch({
currentTranslations: insert(currentTranslation),
defaultTranslations: insert(defaultTranslation),
informationCollection: insert(info),
})
);
for 3.8 this is what I've got to do now which seems needlessly verbose
const insert = <T extends SessionInformation | SessionTranslation>(item: T) =>
iif(isTrailer, insertItem<T>(item as NoInfer<T>), append<T>([item] as NoInfer<T[]>));
Is there something I'm missing here or is it this complex now?
A couple more examples
const move = (collection: Array<SessionTranslation | SessionInformation>) => {
const item = collection.find((x) => x.id === id);
const index = collection.indexOf(item);
return iif(index >= 0 && !!item, compose(removeItem(index), insertItem(item, 0)));
};
// to
const move = <T extends SessionInformation | SessionTranslation>(collection: Array<T>) => {
const item = collection.find((x) => x.id === id);
const index = collection.indexOf(item);
return iif(index >= 0 && !!item, compose(removeItem<T>(index), insertItem<T>(item as NoInfer<T>, 0)));
};
const patchSeries = () => updateManyItems(() => true, patch({ isActive: content.isActive, isPublic: content.isPublic }));
setState(
patch({
showSeriesInformationCollection: patchSeries(),
})
);
// to just doing it inline instead of having the self-documenting function name
setState(
patch({
showSeriesInformationCollection: updateManyItems(
() => true,
patch({ isActive: content.isActive, isPublic: content.isPublic })
),
})
);
Let me know if I'm overcomplicating something. This is what we used to have in 3.6
for 3.8 this is what I've got to do now which seems needlessly verbose
Is there something I'm missing here or is it this complex now?
A couple more examples