Last active
October 6, 2019 22:41
-
-
Save matthewstokeley/c19f3df4977bb982cc4ed1b45f464fe3 to your computer and use it in GitHub Desktop.
very quick sketch of several services to provide transformation to paragraphs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*--------------------------------- | |
* | |
* Real-time data analysis library | |
* @ht lewitt | |
*/ | |
// modularizing paragraphs and allowing granular control over transformation | |
type TransformationObject { | |
count: Number | |
} | |
type MatchEvent { | |
key: String, | |
name: String, | |
fn: Function, | |
writeable: Boolean, | |
enumerable: Boolean | |
} | |
type StreamEvent { | |
} | |
// like a happening | |
type FluxishEvent { | |
} | |
// flux / redux state-based event model | |
const EVENTS = { | |
'EVENT_NAME': '' | |
} | |
const eventsApi = function() {} | |
const STATE_API = { | |
'STATE_KEY': { | |
"OBJ": "CURRENT_STATE" | |
} | |
} | |
// @todo | |
// undefined hashing algorithm | |
function ha = () => {} | |
function retrieveMatchEvent(): Function { | |
const salt = '' | |
let cache = new WeakMap() | |
// what we want to do is add a layer of abstraction between the index | |
// and the function that retrieves the index | |
// so this is a simple robust example of a conditional using the nullish operator to either retrieve or set an item in our cache | |
return ( index: Any ): Function => { | |
return cache.get( index ) ?? cache.set( index ) | |
} | |
// hashes + salts are commonly used to store sensitive information in databases. | |
// a simple example | |
// hash = ha( salt ) | |
const keyResolver = ( function( salt ) { | |
return function( hash: String, resolver: Function ) { | |
let key = resolver( hash, salt ) | |
cache.get( key ) | |
} | |
} ) ( salt ) | |
} | |
const objWriter = function( obj ) { | |
return Object.defineProperty( obj, { | |
name, | |
key, | |
writeable, | |
enumerable | |
} ) | |
} | |
// analysis methods | |
const mle = ( function( ) { | |
} ) ( ) | |
const wc = ( function( ) { | |
} ) ( ) | |
const match = ( function( obj: TransformationObject ): Object { | |
let analysis = {} | |
const mle = function() {} | |
return { | |
} | |
} ) ( ); | |
const transformationObjFactory = function() { | |
return { | |
} | |
} | |
// proof of concept | |
const eventService = ( function(): Object { | |
const events = [] | |
const add = ( function(): Function { | |
return function( name, fn ) { | |
events.push( { | |
name, | |
fn | |
} ) | |
} | |
} )() | |
const emit = ( function( name ): Function { | |
let emittable | |
for ( let i = 0; i < events.length; i++ ) { | |
if ( events[ i ].name === name ) | |
emittable = events[ i ] | |
} | |
return function() { | |
return emittable.fn.call( this, ...args ) | |
} | |
} )() | |
return { | |
add, | |
emit | |
} | |
} )() | |
// run events as child processes | |
const eventsSpawningWrapper = ( function() { | |
return eventService | |
} )() | |
const corpusServiceFactory = ( function( ) { | |
const definition = ( fn ) => { | |
// decorator fn | |
return fn | |
} | |
const generateBson = ( fn ) => { | |
} | |
return ( function() { | |
const corpus | |
const build = function( string, delim = '<p>' ) { | |
corpus = string.split( delim ) | |
} | |
const buildTable = function() { | |
let table = {} | |
let bson = generateBson( i ) | |
for ( let i = 0; i < corpus[ i ]; i++ ) { | |
table[ bson ] = { | |
'_id': bson, | |
'value': corpus[ i ], | |
'index': i | |
} | |
} | |
return table | |
} | |
const get = function() { | |
return corpus | |
} | |
const getByCount = function() {} | |
const findByIndex = function( index ) { | |
return corpus[ index ] | |
} | |
const findByString = function( string ) { | |
// @todo a more efficient string matching service | |
for ( let i = 0; i < corpus.length; i++ ) { | |
if ( corpus[ i ] === string ) | |
return { | |
value: corpus[ i ], | |
index: i, | |
array: corpus | |
} | |
} | |
} | |
const findByBson = function( _id ) { | |
return table[ _id ] | |
} | |
const buildParagraphMetadata = function() {} | |
const save = function() {} | |
return { | |
build, | |
get, | |
getCount, | |
findByIndex, | |
findByString | |
} | |
} )( ) | |
} )( ) | |
const corpusService = corpusServiceFactory() | |
// logic | |
corpusService = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment