During my tenure at the last company, I didn't let my career stagnate as others have and as time moved along.
When at work or home, spend 10% of your time learning something new about some aspect or segway of your job so that your skills are marketable in case you lose it. From experience let me reinforce that it pays off. It pays off in your current job because of the education received and the competence increase of your skills which applied will bring recognition.
In these days and times, loyalty to a company is truly at an end. However many companies do care about cultivating their employees which creates a brand of loyalty that can't be replaced. Old companies with the Corp. mentality (or because of the corp. mentality) ever decrease their budgets on organizational sections and thereby do a RIF as a matter of business.
The mistakes they make during this process can be risky. But who am I, but a lowly ole programmer, to judge risk. If you are laid off, be friendly with your past manager, and based on simple questions and help, give whatever help you can over the phone even though you are under no obligation to do so.
It is also quite possible that there are opportunities to make at home with a new company in the future. Just remember that when inquiring about a position, take advantage of the training that is offered, and keep yourself emotionally and educationally fit.