In topology, continuity is defined as:
A function $f:X\rightarrow Y$ is continuous if the inverse image of an open set in $Y$ is an open set in $X$.
I have a problem to use it to check the non-continuous function. For example, in J.Munkres' book Topology (2nd Edition) (Pg.109), there is an example $$f(x)=\begin{cases} x-2, & x<0\\ x+2, & x\geq0 \end{cases}$$ The domain of this function (i.e. the $X$ in the definition) is $\mathbb{R}$, i.e. $x\in(-\infty,\infty)$; the codomain (i.e. the $Y$ in the definition) is $(-\infty,-2)\cup[2,\infty)$. To prove this function is discontinuous at $x=0$, the book choose the open set of $f$ as $(1,3)$, and thus the inverse image is $[0,1)$, which is not an open set.
The problem is:
the open set $(1,3)$ is not the subset of the codomain $(-\infty,-2)\cup[2,\infty)$. How can we choose it?
In my point of view, within the codomain $(-\infty,-2)\cup[2,\infty)$, all allowed open sets are either within the subset $(-\infty,-2)$ or within the subset $[2,\infty)$. Within these two parts, the function are always continuous. How can we prove the discontinuous?