Img tag handler for incorrect image link
hey, Let’s say you have image tag and src link appears to be incorrect one: image does not exist for that address. We can use onError img attribute to add handler for this situation. Below I will add React code as example. In the snippet, we added fallback in case our src is not available.
Setting cross-domain cookie problem
Safari ships with conservative cross domain cookie policy. It means that if website on safari calls other api on other domain and this api returns set-cookie header, it will not work on Safari, cookie will not be set eventually. Having this issue in my recent project I had to come up with a workaround. Proxy […]
What is endfunctor and functor in Javascript? The easiest explanation.
So what is functor? A functor is a container of type a that, when subjected to a function that maps from a→b, yields a container of type b. https://stackoverflow.com/a/2031430/2706861 In functional programming, a functor is a design pattern inspired by the definition from category theory, that allows for a generic type to apply a function inside without changing the structure of the generic type. Wikipedia …and endfunctor? Endofunctor: A […]
async Functions in for loop
Now this interview question is very popular: The result of this code is ten times repeated 10. The value of i in each function callback is window.i, because var creates global variable. This moment is not obvious on my opinion: for(var i… is is nothing different than var i. So, how to save value of […]
Custom Element in Array type in Typescript
Sometimes you need to do something like this: The issue here is, that most probably makes hard for your fellow developer to read and understand that code because he/she does not expect array type to contain any custom fields. But still you might have reasons to do that, for example, ‘someArray’ is created in other […]
Why ES6 class in Javascript: methods are stored in prototype, but fields are in instance
Let’s create Javascript class and object with this new class: class Rectangle { constructor(height, width) { this.height = height; this.width = width; } getHeight() { return this.height } state = ‘some state’ } const rect = new Rectangle(1, 2); rect._proto_.state undefined rect._proto_.getHeight ƒ getHeight() { return this.height } rect.state ‘some state’ As you see, methods […]
How to pass data to Angular components?
Today I would like to discuss two methods of sharing state between components. Say, we have record detail page, which is page for viewing record data. It has summary component inside. 1) Container – component design pattern. Here Container deals with data fetching and passes the data to subcomponent. After closing page fetched data gets […]
Why unsubscribe in Angular?
Why do you need to unsubscribe of observables in OnDestroy hook? Observable can emit multiple values, so if you want to stop evaluating logic after destroying (closing) component you would need to call unsubscribe If component is closed and request is still pending the unneeded logic could evaluate after component is closed And sometimes it […]