Object.keys(states).forEach((property, i) => { switch (propertyType(child)) { case 'valued-state': case 'described-states': break; } if (isState(property)) { // First generation can only be a category, entity or stateEntity if (isTypeOfState(property))
{ throw new Error('A root node can not be a state'); } // Create short hand } else { // Is it a category or an entity? const hasState = Object.keys(states[property]).some(childProperties => isState(childProperties)) console.log(property, hasState) $[property]
= hasState ? () => {} : {} } switch (propertyType(property)) { case 'state': if (i === 0) { throw new Error('A root node can not be a state'); } else { // Add state to entity } break; case 'stateEntity': break; } }); // Check if children has states. if
(isType(a, 'object')) { const baseProp = a; const property = b; const parent = paseProp[property]; if (isType(parent, 'object')) { const parentHasState = Object.keys(parent).some(child => { switch (propertyType(child)) { case 'valued-state': case 'described-states':
return true; default: return false; } }); if (parentHasState) { // add function } else { // add object } } }
JavaScript
const liveConfig = {};
const initalState = {};
const records = [];
const emphasis = ['_', '$'];
const isArrowFunction = fn => typeof fn === 'function' && fn.prototype === undefined;
const isType = (value, expectedType) => ({}).toString.call(value) === `[object ${(expectedType[0] || '').toUpperCase()}${expectedType.slice(1)}]`;
const isState = property => ['_', '$'].some(char => property.includes(char));
const isTypeOfState = property => ['_', '$'].some(char => property[0] === char);
const propertyType = (property, type) => {
const _ = '_';
const $ = '$';
if (property === _) {
return type ? 'local-handler' === type : 'local-handler';
};
if (property.startsWith(_)) {
return type ? 'valued-state' === type : 'valued-state';
}
if (property === $) {
return type ? 'described-states' === type : 'described-states';
}
if (property.endsWith(_)) {
return type ? 'valued-entity' === type : 'valued-entity';
}
if (property.endsWith($)) {
return type ? 'entity-with-described-states' === type : 'entity-with-described-states';
}
return type ? 'category' === type : 'category';
}
const o = (value, handler) => typeof handler === 'function' ? {
handler,
value,
member$hip: '_$$$_SVH'
} : {
value,
member$hip: '_$$$_SV'
};
/**
*
*
* @param {Function} -
*/
const soucouyant = (config) => {
const hasStates = config.hasOwnProperty('states');
const hasCollections = config.hasOwnProperty('collections');
const hasInitial = config.hasOwnProperty('initial');
// Must have an inital configuration.
if (!hasInitial) {
throw new Error('An intial configuration must exist');
}
// Initial config must be an object.
if (!isType(config.initial, 'object')) {
throw new Error('The intial configuration is not an object');
}
// Create State Management function.
const $ = {} // = () => {};
// State management.
if (hasStates && hasInitial) {
const statesCall = config.states;
const stateIsArrowFn...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.