Viewing version 0.11.9. Open the latest package page.

hub

0.11.9

a collection of static helpers

Download archive

Readme

#Hub ####Description: a simple library containing static helpers

####Helpers

###### ClientSideOnly:
	JStripe: provides a object that maps a dart object to JsObject and add functions that bind to values or
	functions of that JsObject or its inner values

##### Both
	State: provides an object that has a set level of functions that run when activate
	
	StateManager: provides a higher level object that uses state objects as a means of manager state
	
	Switch: a basic object with a on or off state,allowing to do a truthy or falsy checker
	
	Distributor: a basic list that accepts functions and then propagates a value to all when its emit method is called
	
	Transformable: takes a function and passes all values to that function for mutation
	
	SymbolCache: a simple factory of symbols which caches them on creation for reuse
	
	MapDecorator: a decorates a map with get,update,destroy calls
	
	SingleLibraryManager: allows grabbing a library definition from the current MirrorSystem
	
	Counter: a simple class that provides a increment,decrement function calls
	
	SparceList: provides a means of adding items into an array at any position,underneath it uses a map,which turns into an array when calling its toList method
	
	Mutator: a simple object that takes a set of functions,
		 where each results from the previous mutates the value used to call the next one.
	
	Injector: provides a base class for activation of a routine depending on the truthy or falsy value of
		a condition function, eg 
		ListInjector: takes items into array and when the condition set is matched,ejects those values out
		PostionInjector: injects into specific position of an array and when it matches the required condition,ejects the array
		LengthInjector: takes values into an array and if length matches its specified value,ejects a new array with the values it received

####Static Helpers map, eachSync,eachAsync,eachSyncMap,eachAsyncMap,filterValues,filterKeys,compose

createMessageMatcher: creates a function that checks the truthy state of a function with a value and returns true or a map with a predefined message of failure

randomString: takes a number and generates an array containing random strings for each index of the array

cycle: runs a function for a specified number of times

merge: merges to maps into a new map,a basic union operation,allows values destructions 

quickSort: provides a restrictive quicksort algorithm on a list

findMiddle: finds the middle value's index in a list of numbers

classMirrorInvokeNamedSupportTest: checks wether the current mirror system allows using named arguments

findLibrary, findClass: finds a class/library with the mirrorsystem

switchUnless: checks if a value is null and switches a default value for it else returns that value

encryptNamedArguments: turns a Map<String,dynamic> into a Map<Symbol,dynamic>

decryptNamedArguments: turns a Map<Symbol,dynamic> into a Map<String,dynamic>

encryptSymbol: turns a string into a symbol

decryptSymbol: turns a symbol into a string

dualPartial: takes a function and returns a function that awaits 2 values which it then runs on the supplied function,a basic partial for 2 values

dualCurry: takes a function and awaits supply of its arguments in a backward(right to left manner), a basic two value curry function

matchMapConditions/matchListConditions: takes a set of functions and runs a value on them,returns a future that completes with an error if any condition function fails

captureMapConditions/captureListConditions: takes a set of functions and runs a value on them,returning a map/list of the return values for those functions,
	allows doing a condition matchers that return errors or messages on why a value failed to pass a condition

compose: takes two functions and binds the return a new function that binds the return value of one as the input of the other

... and much more

####Example:

	Map<Symbol,dynamic> a = new Map<Symbol,dynamic>();
	Map<String,dynamic> b = new Map<String,dynamic>();
	var cache = Hub.createSymbolCache();
	
	var c = cache.create('c');
	a[new Symbol('a')]='aa';
	b['b']='ba';
		
	assert(cache.create('c') == c);
	assert(Hub.decryptNamedArguments(a) is Map<String,dynamic>);
	assert(Hub.encryptNamedArguments(b) is Map<Symbol,dynamic>);
	
	Hub.captureEachFuture([1,2,3,4,5,6],(n){ if(n != null) return n * 4; }).then((_){
		assert(_.first == 4);
		assert(_.last == 24);
		assert(_.length == 6);
	});
	
	var dist = Hub.createDistributor('example');
  
	dist.on((n){ assert(n is num); });
  
	dist.whenDone((n){  assert(n is num); }); 
	
	dist.emit(4);
	dist.emit(6);
	
	var mutate = Hub.createMutator('mutator');
	mutate.on((n){ return n*4; });
	mutate.on((n){ return n+2; });
	mutate.on((n){ return n/2; });
  
	mutate.whenDone((n){
	   assert(n is num);
	});
	 
	mutate.emit(2);
	mutate.emit(100);
	mutate.emit(1);
	mutate.emit(50);
	 
	var jector = LengthInjector.create(4);
	jector.on((n){
	   assert(n.length == 4);
	});
	  
	jector..push(1)..push(2)..push(3)..push(4);
	var poster = PositionInjector.create(4,(t,c){
	   if(t.length > 3) return true; return false; 
	});
	poster.on((n){
	   assert(n.first == 'sucker');
	   assert(n.length == 4);
	});
	 
	poster..push(0,'sucker')..push(4,'logger')..push(3,'ruber')..push(2,'caller');
	 
	//i noted that its preferable to set the 0 index element at the first of the call or as a separate call,
	//if push(0,item) is put on the last of the .. chain,it will default into an index error,not my fault,its
	//the Map add function system.
	poster.push(0,'crocker');
	poster..push(10,'soccer');
	 
	
	var sparce = SparceList.create();
	sparce.add(0,'john');
	sparce..add(2,'alex')..add(1,'john')..add(5,'mary');
	
	 assert(sparce.sorted().first == 'john');
	 
	var rand = new math.Random();
	var f = null;
	 
	assert(Hub.merge({'a':1},{'a':4,'b':2},override: false)['a'] == 1);
	assert(Hub.merge({'a':1},{'a':4,'b':2})['a'] == 4);

	assert(Hub.filterValues(Hub.map([1,3,32],(e,i,o) => e*3),(e,i,o){ 
	    if(e%2 == 0) return true; 
	    return false; 
	})[0] == 96);

	var isString = Hub.createMessageMatcher('isString','is not a string!',(a){
	    if(a is String) return true;
	    return false;
	});
	  
	assert(isString('alex') == true);
	assert(isString(1) is Map);	
	
	var sum = Hub.dualPartial((a,b) => a+b);
	var diff = Hub.dualCurry((a,b) => a-b);
  
	assert(sum(1)(2) == 3);
	assert(diff(2)(1) == 1);


	var play = State.create({ 'name':'alex','paused': false},{
	  'play': (target,controller){ print('${target['name']} playing song? isPaused: ${target['paused']}'); },
	  'pause': (target,controller){ target['paused'] = true; controller.run('play'); }
	},'player');
	
	var man = StateManager.create(play);
	man.add('play',{
	  'play':(target,control){ target.activate(); target.run('play'); },
	  'pause':(target,control){ }
	});
	man.add('pause',{
	  'play':(target,control){ },
	  'pause':(target,control){ target.run('pause'); target.deactivate(); }
	});
	
	play.run('play'); -> runs the current state play function
	//  man.switchState('play');
	//  no reaction since state is null
	man.run('play'); 
	man.run('pause');
	//switching to play state
	man.switchState('play'); -> if state was pause then calls pause.deactivate(),switches state to play & calls play.activate()
	//should get response with play but not pause
	man.run('play'); 
	man.run('pause');
	//switching to pause state
	man.switchState('pause');
	//pause should respond not play
	man.run('play'); man.run('pause');	
	
	--------------------------------------------- clientside only-----------------------------------------
	
	var strip = JStripe.create(new IFrameElement());
	//adds the contentWindow attribute of the iframe to the targetable list
	strip.fragment('contentWindow');
	
	//add a method fragment for the root element i.e the iframe, for the name attribute
	strip.methodFragment('root','name');

	//add a wrapper for contentWindow.addEventListener but tag it addEvent
	strip.methodFragment('contentWindow','addEvent','addEventListener');
	
	//add a wrapper for contentWindow.addEventListener,no tag hence name it addEventListener
	strip.methodFragment('contentWindow','addEventListener');
	

	//run the name tag of the root
	strip.runOn('root','name')(); => returns the value of name (Iframe.name)

	//run the addEvent tag for contentWindow with arguments [message,Function]
	strip.runOn('contentWindow','addEvent')(['message',(e){
		var message = e['data'];
		print(message);
	},false]);
	
	//run the addEventListener tag for contentWindow with first argument 'message',then supply argument Function,
	//basically we can supply the first argument of that array above,and just supply a single value to the return function
	// which turns that into the above ['message',Function]
	strip.runOn('contentWindow','addEventListener','message')((e){
		print(e['data']);
	});
	
	//applies also for

	strip.runOn('contentWindow','addEvent','message')((e){
		var message = e['data'];
		print(message);
	},false]);
Changelog

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'hub:0.11.9'
pubspec.yaml
name: hub
version: 0.11.9
author: Ewetumo Alexander Adeniyi <trinoxf@gmail.com>
description: a collection of static helpers
homepage: https://github.com/influx6/hub
dependencies:
  browser: any

Version history

VersionPublishedArchiveSHA-256
0.0.1Cached · Upstream SHA-256 matchedDownload8fd90304…5cb1a2
0.1.0Cached · Upstream SHA-256 matchedDownloadbf57212d…4c6718
0.1.1Cached · Upstream SHA-256 matchedDownload96ce8409…c70e84
0.1.2Cached · Upstream SHA-256 matchedDownloadb9ab6c9b…4c6576
0.1.3Cached · Upstream SHA-256 matchedDownload0c6c242f…f236ca
0.2.0Cached · Upstream SHA-256 matchedDownloade97df42a…041850
0.3.0Cached · Upstream SHA-256 matchedDownloadd2ef8b96…317c99
0.4.0Cached · Upstream SHA-256 matchedDownload1c22c51d…b02d98
0.5.0Cached · Upstream SHA-256 matchedDownload95184f28…c506cf
0.5.1Cached · Upstream SHA-256 matchedDownload34a6ad79…8babfa
0.5.2Cached · Upstream SHA-256 matchedDownload624dee44…309942
0.5.3Cached · Upstream SHA-256 matchedDownload7cf5c547…1f582c
0.5.5Cached · Upstream SHA-256 matchedDownload2e382c8a…5392b4
0.5.6Cached · Upstream SHA-256 matchedDownloadb8277fa6…9002b7
0.5.7Cached · Upstream SHA-256 matchedDownload9e44aa6e…b2dac4
0.5.8Cached · Upstream SHA-256 matchedDownload882a6f2e…0dca4e
0.5.9Cached · Upstream SHA-256 matchedDownload3cb5fa3b…36d77a
0.6.0Cached · Upstream SHA-256 matchedDownload72dd47f0…8c8e7e
0.6.1Cached · Upstream SHA-256 matchedDownloadbf9593a4…4b5f8e
0.6.2Cached · Upstream SHA-256 matchedDownloadd9ca3c99…d36d1d
0.6.3Cached · Upstream SHA-256 matchedDownload8cb78a8c…dfd6f9
0.6.4Cached · Upstream SHA-256 matchedDownloadb1faa718…948ba8
0.6.5Cached · Upstream SHA-256 matchedDownload82a82e57…ec3989
0.6.6Cached · Upstream SHA-256 matchedDownloada7664d95…a4f8bb
0.6.7Cached · Upstream SHA-256 matchedDownloadf66a9983…593b99
0.6.8Cached · Upstream SHA-256 matchedDownload72d330e6…8be348
0.6.9Cached · Upstream SHA-256 matchedDownloadaccfe929…fd248c
0.7.0Cached · Upstream SHA-256 matchedDownload593fab2c…935d56
0.7.2Cached · Upstream SHA-256 matchedDownload6c9e7bf8…d59cd0
0.7.4Cached · Upstream SHA-256 matchedDownloadbf6193fd…003208
0.7.5Cached · Upstream SHA-256 matchedDownload89c29936…57369f
0.7.6Cached · Upstream SHA-256 matchedDownloadb39664b7…179517
0.7.7Cached · Upstream SHA-256 matchedDownload6c948367…e380b9
0.7.8Cached · Upstream SHA-256 matchedDownload5fdcc0c6…124c39
0.7.9Cached · Upstream SHA-256 matchedDownload5f553e18…cf5db5
0.8.0Cached · Upstream SHA-256 matchedDownload9e4ba2ab…1e6d46
0.8.1Cached · Upstream SHA-256 matchedDownloadbec8051d…13ab0d
0.8.2Cached · Upstream SHA-256 matchedDownload71d0fc57…4cba30
0.8.3Cached · Upstream SHA-256 matchedDownload6ae483d1…bd9f66
0.8.4Cached · Upstream SHA-256 matchedDownload2f6576c6…550748
0.8.5Cached · Upstream SHA-256 matchedDownload7cfd09f2…78d4b3
0.8.6Cached · Upstream SHA-256 matchedDownload3ba2cafb…11c788
0.8.7Cached · Upstream SHA-256 matchedDownload53e8c2fa…d8cb7c
0.8.8Cached · Upstream SHA-256 matchedDownload368bde42…79b219
0.8.9Cached · Upstream SHA-256 matchedDownload588f49a6…3fdcd9
0.9.1Cached · Upstream SHA-256 matchedDownload98287d68…7ff333
0.9.3Cached · Upstream SHA-256 matchedDownload5ecad9c9…5a3f6d
0.9.4Cached · Upstream SHA-256 matchedDownload0b113a30…65151d
0.9.5Cached · Upstream SHA-256 matchedDownload5e84b95b…2468a9
0.9.6Cached · Upstream SHA-256 matchedDownload7c9532d4…11128d
0.9.7Cached · Upstream SHA-256 matchedDownloadb563daf4…e8ab70
0.9.8Cached · Upstream SHA-256 matchedDownload09025dbe…bff68d
0.9.9Cached · Upstream SHA-256 matchedDownloade8561786…427774
0.10.0Cached · Upstream SHA-256 matchedDownload6b80ebeb…388c41
0.10.1Cached · Upstream SHA-256 matchedDownload7cead8a7…d56f09
0.10.2Cached · Upstream SHA-256 matchedDownload3ef72489…f17033
0.10.3Cached · Upstream SHA-256 matchedDownloada4baf5b4…0c6468
0.10.4Cached · Upstream SHA-256 matchedDownload877380cc…cb12dd
0.10.6Cached · Upstream SHA-256 matchedDownloadc37896d1…6e0001
0.10.7Cached · Upstream SHA-256 matchedDownload728d0269…86aaec
0.10.8Cached · Upstream SHA-256 matchedDownload5970ce45…6d7124
0.10.9Cached · Upstream SHA-256 matchedDownload6f5f2efb…21bf42
0.11.0Cached · Upstream SHA-256 matchedDownload78de0f52…a241a1
0.11.1Cached · Upstream SHA-256 matchedDownload6281be4c…ebfa5c
0.11.2Cached · Upstream SHA-256 matchedDownload4fd902ce…0aa891
0.11.3Cached · Upstream SHA-256 matchedDownloadd631ee7f…1e42ad
0.11.4Cached · Upstream SHA-256 matchedDownloaded4c3976…a49af7
0.11.5Cached · Upstream SHA-256 matchedDownload7c0e29ad…604ddf
0.11.6Cached · Upstream SHA-256 matchedDownload43c39ebf…4fc7e8
0.11.7Cached · Upstream SHA-256 matchedDownload80803ffa…8d0263
0.11.8Cached · Upstream SHA-256 matchedDownload6a2d7d99…ee352b
0.11.9Cached · Upstream SHA-256 matchedDownload3d4d8c79…8c5292
0.12.0Cached · Upstream SHA-256 matchedDownload512f4814…ebb3dc
0.12.1Cached · Upstream SHA-256 matchedDownload0bb8d7d5…4c92d5

Dependencies

browser "any"