import { getFootures } from './core';

const ALL_FEATURES: Array<string> = [];

function isEnabled(feature: string) {
  const specifier: object = getFootures();

  if (ALL_FEATURES.indexOf(feature) === -1) {
    // Not registered yet, 
    ALL_FEATURES.push(feature);
  }

  return !!specifier[feature];
}

/**
 * Register features. Allows the admin UI to be generated with checkboxes.
 *
 * @param {array} features An array of features spread out like a variadic function.
 */
function register(...features) {
  const specifier: object = getFootures();

  features.forEach((feature) => {
    if (ALL_FEATURES.indexOf(feature) === -1) {
      ALL_FEATURES.push(feature);
    }
  });
}

function getAllFootures() {
  return ALL_FEATURES;
}

// footures.isEnabled('foo') and footures.register('foo', 'bar');
export default { register, isEnabled, getAllFootures };
export { register, isEnabled, getAllFootures };

import { getFootures, setFootures } from './core';

class FootureSpecifier {
  __all: Array<string>
}

/**
 * Adds feature to an internal list. Could be used to show UI.
 * @param feature Mark feature as having been used.
 */
function footureUsed(feature: string) {
  const specifier: FootureSpecifier = getFootures();

  if (!specifier.hasOwnProperty('__all')) {
    specifier.__all = [];
  }
  
  if (specifier.__all.indexOf(feature) === -1) {
    specifier.__all.push(feature);

    setFootures(specifier);
  }
}

function isEnabled(feature: string) {
  const specifier: FootureSpecifier = getFootures();

  footureUsed(feature);
  return !!specifier[feature];
}

/**
 * Register features. Allows the admin UI to be generated with checkboxes.
 *
 * @param {array} features An array of features spread out like a variadic function.
 */
function register(...features): void {
  const specifier: object = getFootures();

  features.forEach(footureUsed);
}

function getAllFootures(): Array<String> {
  const specifier: FootureSpecifier = getFootures();
  return specifier.__all;
}

// footures.isEnabled('foo') and footures.register('foo', 'bar');
export default { register, isEnabled, getAllFootures };
export { register, isEnabled, getAllFootures };

Use localStorage for *all* footure declarations
Use localStorage for *all* footure declarations
