God has two main records or registers: the Supreme Preserved Tablet (corresponding to Destiny or Divine Knowledge) and the Manifest Record (corresponding to the reality of time). The Supreme Preserved Tablet never changes, since God also has absolutely unrestricted Will and is therefore not restricted by the Destiny He established for His creatures. However, He may change what He records in the Manifest Book: God effaces whatever He wills and confirms whatever He wills, with Him is the Mother of the Book (13:39).
This subtle matter is difficult to understand. Although we cannot fully understand the reality of this effacement and confirmation, we frequently witness it in our lives. For example, one day we leave home with the intention of going to a place where sins are freely committed. However, out of His mercy and favor, God arranges for us to meet some good friends who persuade us to go to a good place. Likewise, we commit sins too freely and therefore are subject to misfortune. But instead of dealing with us from His Justice, God, out of His grace, treats us with utmost grace and pardons us, thereby saving us from misfortune.
Divine Grace exists so that we will not despair of being forgiven, so that we may turn to Him despite our sins, and so that we should not see ourselves as absolutely bound by the consequences that Divine Destiny and Decree establishes for our deeds. This is made explicit in the following verses:
Whatever misfortunes befalls you, is for what your own hands have earned, and for many (of them) He grants forgiveness. (42:30)
If God were to punish people for their wrongdoing, He would not leave on the Earth a single living creature; but He reprieves them to an appointed term. (16:61)
Relate [to them from Me): "O My slaves who have transgressed against their selves! Do not despair of God's mercy! Surely God forgives all sins, for He is the All-Forgiving, the Most Compassionate. (39:53)
Divine grace or liberality manifests itself more clearly in human history. As we are responsible and accountable for our acts, we direct our own history. Such historical philosophies as historicism are quite mistaken, for there is no determination in history or historical events.
Many historical people, such as those 'Ad, Thamud, and Pharaoh, deserved to perish because of their dissolute lifestyles, injustice, and atrocities. And so God eradicated them. However, Prophet Jonah's people, upon him be peace, turned to God with utmost sincerity and deep repentance, and reformed themselves morally after they saw signs of impending destruction. As a result, God spared them the penalty of disgrace in the life of this world, and gave them comfort for a while (10:98). Emphasizing this point, God's Messenger, upon him be peace and blessings, said: "Fear does not prevent misfortunes, but prayer and charity prevent them." 
Therefore, believers should never cease praying and giving charity. When they feel misfortune coming, they should immediately turn to God in prayer, repent, give charity, or perform some service for Islam.