@joystick.js/ui

cache.unset()

How to use the cache.unset() method to clear an existing cache.

Once you have an existing cache, to clear the current value, you can utilize the .unset() method (defined on the object returned when initializing the cache).

Example Usage

ui/components/player/index.js

import joystick from '@joystick.js/ui';

const Player = joystick.component({
  events: {
    'click .clear-player': (event = {}, instance = {}) => {
      window.player_state.unset();
    },
    'click .play': (event = {}, instance = {}) => {
      ...
    },
    'click .pause': (event = {}, instance = {}) => {
      ...
    },
  },
  render: ({ props, state }) => {
    return `
      <div class="player">
        <header>
          <ul>
            <li class="previous"><i class="mod-icon-skip-back"></i></li>
            <li class="${props?.state?.playing ? 'pause' : 'play'}">
              <button>${props?.state?.playing ? 'pause' : 'play'}</button>
            </li>
            <li class="next"><i class="mod-icon-skip-forward"></i></li>
            <li class="clear-player"><i class="mod-icon-x"></i></li>
          </ul>
        </header>
        <footer>
          <div class="progress-bar">
            <div class="progress" style="width: ${(state?.player?.current_time / state?.player?.total_time) * 100}%;"></div>
          </div>
        </footer>
      </div>
    `;
  },
});

export default Player;

API

Definition

cache.unset(path: string, user_event_label: string) => undefined

Parameters

path string
An dot-notated path (e.g., 'player.playing') for a specific value in the cache you want to unset.
user_event_label string
A custom label for the change being made to the cache that's passed to event listeners to identify the change.