p-hatan/ mirror

pub repository

mirror.p-hatan.com

hub

0.6.4

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

####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.com
flutter pub add hub
pubspec.yaml
name: hub
author: Ewetumo Alexander Adeniyi <trinoxf@gmail.com>
version: 0.6.4
homepage: https://github.com/influx6/hub
description: a collection of static helpers

Version history

VersionPublishedArchiveSHA-256
0.0.12013-08-04T19:19:15.767780ZDownload8fd90304b0d9fd08c77a088baeada1e23850c7aad4bfad9ecc845258cb5cb1a2
0.1.02013-08-08T07:27:54.324600ZDownloadbf57212d6d7ecba6f2c0a2db3d9b45fc940356c33991dfb647021194224c6718
0.1.12013-08-13T06:00:27.587300ZDownload96ce84095208b93de51cd320a32e1d1fa4a47b13313c4668fd85052cd1c70e84
0.1.22013-09-16T21:24:47.496700ZDownloadb9ab6c9b1ebe8d3eddf80ff7b2ee74e0994347211230d2995a5ed984f14c6576
0.1.32013-12-06T11:17:28.225910ZDownload0c6c242ff3c04b6100c095b3e71e11e4e53d8f7a99863e286bb4e09f7af236ca
0.2.02014-01-18T12:23:32.168980ZDownloade97df42aacda811230e10b5c9feb7aaf96fd660d41f77fa11fc1486abd041850
0.3.02014-01-23T11:13:47.028020ZDownloadd2ef8b9655bcb700eab554228b3776e35440c0267a1b3e8b437108f3c9317c99
0.4.02014-01-24T10:17:23.727420ZDownload1c22c51dfb8ba52759377226552894144331c75a8d8acc792141525ed4b02d98
0.5.02014-01-26T06:25:38.916160ZDownload95184f28b9d1a2850ee776efe0aaa3d6bc686f1acb532af043d5a04ff1c506cf
0.5.12014-01-26T06:37:47.195710ZDownload34a6ad79b9f763a99b699920833bb94c16b60ed28c69f94fb51021e8168babfa
0.5.22014-01-26T19:15:51.017530ZDownload624dee4434052663db9d5d145c3b84fbba9c871a506d646afda3ba2986309942
0.5.32014-01-27T20:26:05.418220ZDownload7cf5c547236a5e8dcbe36342e3c5a7c48966777efe1add46ad4c5cc5771f582c
0.5.52014-01-28T12:52:02.018770ZDownload2e382c8a9f612b05768986b1d84d28afe071e16e6b21b40ced3198a0225392b4
0.5.62014-01-28T13:07:03.604830ZDownloadb8277fa6f2429c750956913ca2802809c5729cc2e13c1aa6c8b7b823859002b7
0.5.72014-02-01T12:41:14.851140ZDownload9e44aa6ea4f58733ba3ab1728b3240235ba223a209bc1e4d69cca985b4b2dac4
0.5.82014-02-01T13:35:25.431360ZDownload882a6f2efa84d2a247af719fc4bda0f1e33c2edd0313f3ccd183d4dd040dca4e
0.5.92014-02-01T13:48:54.727230ZDownload3cb5fa3bfc76fde09259ef36fb1b42491152d84de4e29f530888a15c8836d77a
0.6.02014-02-01T13:56:06.639810ZDownload72dd47f0796373cc41cb97bfbe82622587a63d39f3c15fc369f129b7f98c8e7e
0.6.12014-02-01T14:39:35.510610ZDownloadbf9593a41b85b96f5215b056238aefd9b5237562262f6c92bb4ccce37f4b5f8e
0.6.22014-02-01T14:53:03.790640ZDownloadd9ca3c993bb6985fb0143cf25b2fc63a735672a690a7b528d0504a729dd36d1d
0.6.32014-02-05T10:26:23.157280ZDownload8cb78a8c480e5072dedcf7aa9b2df4be0ad5ff5cd23877ee92943722b9dfd6f9
0.6.42014-02-06T16:09:54.162470ZDownloadb1faa718b69c4dfec738ef0e1be4ddb65bdd97da94cd4db41ce3db7d5c948ba8
0.6.52014-02-06T16:19:00.024950ZDownload82a82e5773fac1f13a03b2c09878591da2473c4fce279c357a3261d0f9ec3989
0.6.62014-02-06T16:28:46.086270ZDownloada7664d954ce0ec58dd137d33bf3387be04de27f8c3009b3c533c6483a5a4f8bb
0.6.72014-02-08T22:51:28.772400ZDownloadf66a99836b5302d424314b56689b478bcaa24a033757ee8ef0d3e03d85593b99
0.6.82014-02-19T17:47:51.281900ZDownload72d330e6e0c31ef4053f0ed208ae7eaa167e46067bd44ccdafead221438be348
0.6.92014-02-20T16:15:59.792280ZDownloadaccfe929dacd6758f128cb98b76c55abb8b972176b9a0cd4c9b95b4ac6fd248c
0.7.02014-02-20T16:25:32.735460ZDownload593fab2c725d6b5929b36f9c2bb28cd0f5077982a088ef7b7ff6d29a78935d56
0.7.22014-04-08T08:21:04.599870ZDownload6c9e7bf8ea6107a7d0cc775c07155848d40c0e17a7f6e4a51af54a1383d59cd0
0.7.42014-04-09T20:18:08.629600ZDownloadbf6193fd4a54922d9295e95408e85da697083b2d940b41a7268a318ea1003208
0.7.52014-04-13T05:46:09.393120ZDownload89c29936833196c85e2bb7943356ca4fedf664caed840bd6278710006157369f
0.7.62014-05-01T22:18:35.225430ZDownloadb39664b7a2ee710da8cb5ced0cdff44e6fdeef2f8214a42d2ea965fb25179517
0.7.72014-05-16T14:26:48.152130ZDownload6c94836768688321171c1ae9ff9fa588d21108b0b965620868d44a4b76e380b9
0.7.82014-05-16T14:32:37.163550ZDownload5fdcc0c61749bad26214b411710f50ec75b691846f91d072dc1e8f0985124c39
0.7.92014-05-16T17:00:22.099820ZDownload5f553e1899d9547190aa51fcd8680b517207f6c28aaff35c217518b927cf5db5
0.8.02014-05-18T17:23:28.075570ZDownload9e4ba2abbcc5b60bebac1cb2ec8faff0c6a7f8163e2c7141d6a952c96d1e6d46
0.8.12014-05-18T20:53:05.938160ZDownloadbec8051ddd45b923142eaf6bdfc12affecd66958f8e9f5fbe96eac72fe13ab0d
0.8.22014-06-01T15:17:15.551490ZDownload71d0fc57e2bb61e00c001e063180d6951060dcac68d5a5d911a84ffc4a4cba30
0.8.32014-05-22T16:22:34.696660ZDownload6ae483d1664db885b5233b0ca188b873722ae3037134e94adb809f2318bd9f66
0.8.42014-06-01T21:07:06.031380ZDownload2f6576c699e25424c8bf9370cfd8121fbb2b7be53b394aa9b79f4c2b0a550748
0.8.52014-06-08T12:57:02.594670ZDownload7cfd09f28f460f801cc8e90e338d9180a109b836076c5c2aacd860740a78d4b3
0.8.62014-06-18T20:02:56.938360ZDownload3ba2cafb66ee2b5d42afdfaad06decbe66db86e4acca71bb13caee81ef11c788
0.8.72014-06-21T20:28:54.110700ZDownload53e8c2fae50e8e20f5007b2a12e652d7896413c85c02809dc16c223dced8cb7c
0.8.82014-06-23T21:15:09.774040ZDownload368bde421263ce32a478e086969c2c43e7f1b9da21d29aaf5002ec945679b219
0.8.92014-06-23T21:42:51.499600ZDownload588f49a6247e2e9b0aef83461413a324b67303d36195f2ac30784b846b3fdcd9
0.9.12014-06-29T20:59:17.881050ZDownload98287d68f5295ccd1b7c3f0c12e5d2dc63a535409a9eade619d9139d3c7ff333
0.9.32014-08-15T08:43:19.237520ZDownload5ecad9c97efa182e539137af296547852e849482517252a48c07adf4865a3f6d
0.9.42014-08-17T08:02:01.924530ZDownload0b113a3043b8027b4ad106227293c5b7f111b91e5a9713e98d7a308c3f65151d
0.9.52014-08-19T08:28:45.706750ZDownload5e84b95b7efa7c0d9965c7f67e32cf90b2f6bd863226f92bd9c32c096d2468a9
0.9.62014-08-19T09:11:43.786060ZDownload7c9532d49e84e9b7116089e0af5de3d495ca752de0551bc02b8fb8837311128d
0.9.72014-08-19T10:34:18.409050ZDownloadb563daf4c9a039a89e2388eb8ad407225d44412bce22087d1168e5a0d9e8ab70
0.9.82014-08-22T17:25:28.724390ZDownload09025dbe85c7f52c8be5571b077afbb222fa9ee3ae358dc2e485419425bff68d
0.9.92014-08-26T11:22:06.587140ZDownloade8561786ccc869142c77e5f547fc5072bf95d05b4e7ef7ab5f24ec3718427774
0.10.02014-08-28T17:49:27.344210ZDownload6b80ebeb024a0996742600090c3e08736634d8811f9982208ffaaa8d55388c41
0.10.12014-08-28T21:41:07.703930ZDownload7cead8a75b9b7d03e7c4ac1ac23f7cbc0f865ffc741c901df64fdc9554d56f09
0.10.22014-09-02T21:10:09.535980ZDownload3ef72489b0ab2746f050eb7e941ceef661b6b2f4f9909b51798e28fdeef17033
0.10.32014-09-02T22:13:36.400360ZDownloada4baf5b4d7c5b8715777cfa8c9fd5580877f093d6b8fce47d588d058db0c6468
0.10.42014-09-03T21:08:58.026970ZDownload877380cc8206d4408f1394906db44bbaf00f4349f22edf1aeb57b62750cb12dd
0.10.62014-09-07T21:34:36.151520ZDownloadc37896d16941b0b6073b226f292f532a4cac00cd11c49c034f3511db916e0001
0.10.72014-09-07T22:11:47.670800ZDownload728d0269174b8a65dcd327da7da7cb5180e13caab3ac6d90faddd9117a86aaec
0.10.82014-09-08T13:32:54.134540ZDownload5970ce45bc801da6eb922737853c189662060de871d04583a6bb79aaae6d7124
0.10.92014-09-08T22:24:28.440020ZDownload6f5f2efb0a6df108808479457edb75f24652fad83c1aedf75e4016b13521bf42
0.11.02014-09-11T14:13:29.934320ZDownload78de0f52b44653e2d008f0b9ee6746adbe471159984ae189fdfb6c5ca8a241a1
0.11.12014-09-12T20:50:05.989470ZDownload6281be4c8527182ab8fe0ea6b4611e14fb0dbb81b80fa4d50315cf4795ebfa5c
0.11.22014-09-12T21:18:02.132390ZDownload4fd902ce81f970c427f70d3a870d907802e274b8e1390b23fcbedf0a6e0aa891
0.11.32014-09-13T14:32:02.261070ZDownloadd631ee7f9985ad428da7605c0f2b7eddd6eddb45f088ddc2bee95393391e42ad
0.11.42014-09-13T16:55:15.082960ZDownloaded4c397625bf6ce4d8c3f8a7dfcfd9b0e2e611616db51785531b659ce9a49af7
0.11.52014-09-13T21:13:57.918550ZDownload7c0e29ad18661b5373d53d2fb19a5496882d61996fb4edd70fdafc442b604ddf
0.11.62014-09-14T20:33:41.724080ZDownload43c39ebff171684aa18f18f46298981bb1ba8ae43967293d25fd329db84fc7e8
0.11.72014-09-14T20:41:08.491210ZDownload80803ffa60b474fdaee137f44edcbde88291de6aceff7c2fae71a154178d0263
0.11.82014-09-15T16:25:55.335040ZDownload6a2d7d994460a78bdb3ba4fb369db854c86a591dde9b99c1ce9ca12a63ee352b
0.11.92014-09-15T20:10:30.002350ZDownload3d4d8c790e8140370ae4b7edd9d25365bb04e846db5c3dacab4dda49b28c5292
0.12.02014-09-16T11:45:10.817430ZDownload512f481422ab5ccbf41bc8751d3e07df25b6353e05aaf3feaa6877c821ebb3dc
0.12.12014-09-18T13:36:50.975440ZDownload0bb8d7d5aabe5364b8aa903f3e349e2877df347a1c8416982a1c95fedc4c92d5

Dependencies

No direct dependencies declared.