bem-contrib / bem-animations

:bell: Easy and Fast in use (based on Animate CSS)
MIT License
13 stars 6 forks source link

Add API: reset #9

Closed belozer closed 8 years ago

belozer commented 8 years ago
    /**
     * Reset all block mods and delete inline styles
     * @return {Bem} this block
     */
    reset: function() {
      for (const mod in this._modCache) {
        if (!this._modCache.hasOwnProperty(mod) || mod === 'js') {
          continue;
        }
        this.delMod(mod);
      }

      this.domElem.css('display', '');
      return this;
    },
belozer commented 8 years ago

Need add full reset flag. Default behavior - delete all mods and styles after "start" function.

belozer commented 8 years ago
    /**
     * Reset block mods and inline styles
     * @param  {Boolean} toLast  to last saved state
     * @return {Bem}             block instance
     */
    reset: function(toLast) {
      this.domElem.css('display', '');

      if (toLast && this._state.last) {
        this._reset(this._state.last);
        return this;
      }

      // Restore inited mods state
      this._reset(this._state.inited);
      return this;
    },

    /**
     * Reset object to state
     * @param {object} state mods
     */
    _reset: function(state) {
      objects.each(state.mods, (val, mod) => {
        if (this._modCache[mod] === val) {
          return;
        }
        this.setMod(mod, val);
      });

      objects.each(this._modCache, (val, mod) => {
        if (state.mods[mod] === undefined) {
          this.delMod(mod);
        }
      });
    },
belozer commented 8 years ago

But I'm starting to think that this functionality is unnecessary...