Viewing version 0.10.1. Open the latest package page.
hub
0.10.1a collection of static helpers
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.10.1'pubspec.yaml
name: hub
version: 0.10.1
author: Ewetumo Alexander Adeniyi <trinoxf@gmail.com>
description: a collection of static helpers
homepage: https://github.com/influx6/hub
dependencies:
browser: any
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.0.1 | Cached · Upstream SHA-256 matched | Download | 8fd90304…5cb1a2 |
| 0.1.0 | Cached · Upstream SHA-256 matched | Download | bf57212d…4c6718 |
| 0.1.1 | Cached · Upstream SHA-256 matched | Download | 96ce8409…c70e84 |
| 0.1.2 | Cached · Upstream SHA-256 matched | Download | b9ab6c9b…4c6576 |
| 0.1.3 | Cached · Upstream SHA-256 matched | Download | 0c6c242f…f236ca |
| 0.2.0 | Cached · Upstream SHA-256 matched | Download | e97df42a…041850 |
| 0.3.0 | Cached · Upstream SHA-256 matched | Download | d2ef8b96…317c99 |
| 0.4.0 | Cached · Upstream SHA-256 matched | Download | 1c22c51d…b02d98 |
| 0.5.0 | Cached · Upstream SHA-256 matched | Download | 95184f28…c506cf |
| 0.5.1 | Cached · Upstream SHA-256 matched | Download | 34a6ad79…8babfa |
| 0.5.2 | Cached · Upstream SHA-256 matched | Download | 624dee44…309942 |
| 0.5.3 | Cached · Upstream SHA-256 matched | Download | 7cf5c547…1f582c |
| 0.5.5 | Cached · Upstream SHA-256 matched | Download | 2e382c8a…5392b4 |
| 0.5.6 | Cached · Upstream SHA-256 matched | Download | b8277fa6…9002b7 |
| 0.5.7 | Cached · Upstream SHA-256 matched | Download | 9e44aa6e…b2dac4 |
| 0.5.8 | Cached · Upstream SHA-256 matched | Download | 882a6f2e…0dca4e |
| 0.5.9 | Cached · Upstream SHA-256 matched | Download | 3cb5fa3b…36d77a |
| 0.6.0 | Cached · Upstream SHA-256 matched | Download | 72dd47f0…8c8e7e |
| 0.6.1 | Cached · Upstream SHA-256 matched | Download | bf9593a4…4b5f8e |
| 0.6.2 | Cached · Upstream SHA-256 matched | Download | d9ca3c99…d36d1d |
| 0.6.3 | Cached · Upstream SHA-256 matched | Download | 8cb78a8c…dfd6f9 |
| 0.6.4 | Cached · Upstream SHA-256 matched | Download | b1faa718…948ba8 |
| 0.6.5 | Cached · Upstream SHA-256 matched | Download | 82a82e57…ec3989 |
| 0.6.6 | Cached · Upstream SHA-256 matched | Download | a7664d95…a4f8bb |
| 0.6.7 | Cached · Upstream SHA-256 matched | Download | f66a9983…593b99 |
| 0.6.8 | Cached · Upstream SHA-256 matched | Download | 72d330e6…8be348 |
| 0.6.9 | Cached · Upstream SHA-256 matched | Download | accfe929…fd248c |
| 0.7.0 | Cached · Upstream SHA-256 matched | Download | 593fab2c…935d56 |
| 0.7.2 | Cached · Upstream SHA-256 matched | Download | 6c9e7bf8…d59cd0 |
| 0.7.4 | Cached · Upstream SHA-256 matched | Download | bf6193fd…003208 |
| 0.7.5 | Cached · Upstream SHA-256 matched | Download | 89c29936…57369f |
| 0.7.6 | Cached · Upstream SHA-256 matched | Download | b39664b7…179517 |
| 0.7.7 | Cached · Upstream SHA-256 matched | Download | 6c948367…e380b9 |
| 0.7.8 | Cached · Upstream SHA-256 matched | Download | 5fdcc0c6…124c39 |
| 0.7.9 | Cached · Upstream SHA-256 matched | Download | 5f553e18…cf5db5 |
| 0.8.0 | Cached · Upstream SHA-256 matched | Download | 9e4ba2ab…1e6d46 |
| 0.8.1 | Cached · Upstream SHA-256 matched | Download | bec8051d…13ab0d |
| 0.8.2 | Cached · Upstream SHA-256 matched | Download | 71d0fc57…4cba30 |
| 0.8.3 | Cached · Upstream SHA-256 matched | Download | 6ae483d1…bd9f66 |
| 0.8.4 | Cached · Upstream SHA-256 matched | Download | 2f6576c6…550748 |
| 0.8.5 | Cached · Upstream SHA-256 matched | Download | 7cfd09f2…78d4b3 |
| 0.8.6 | Cached · Upstream SHA-256 matched | Download | 3ba2cafb…11c788 |
| 0.8.7 | Cached · Upstream SHA-256 matched | Download | 53e8c2fa…d8cb7c |
| 0.8.8 | Cached · Upstream SHA-256 matched | Download | 368bde42…79b219 |
| 0.8.9 | Cached · Upstream SHA-256 matched | Download | 588f49a6…3fdcd9 |
| 0.9.1 | Cached · Upstream SHA-256 matched | Download | 98287d68…7ff333 |
| 0.9.3 | Cached · Upstream SHA-256 matched | Download | 5ecad9c9…5a3f6d |
| 0.9.4 | Cached · Upstream SHA-256 matched | Download | 0b113a30…65151d |
| 0.9.5 | Cached · Upstream SHA-256 matched | Download | 5e84b95b…2468a9 |
| 0.9.6 | Cached · Upstream SHA-256 matched | Download | 7c9532d4…11128d |
| 0.9.7 | Cached · Upstream SHA-256 matched | Download | b563daf4…e8ab70 |
| 0.9.8 | Cached · Upstream SHA-256 matched | Download | 09025dbe…bff68d |
| 0.9.9 | Cached · Upstream SHA-256 matched | Download | e8561786…427774 |
| 0.10.0 | Cached · Upstream SHA-256 matched | Download | 6b80ebeb…388c41 |
| 0.10.1 | Cached · Upstream SHA-256 matched | Download | 7cead8a7…d56f09 |
| 0.10.2 | Cached · Upstream SHA-256 matched | Download | 3ef72489…f17033 |
| 0.10.3 | Cached · Upstream SHA-256 matched | Download | a4baf5b4…0c6468 |
| 0.10.4 | Cached · Upstream SHA-256 matched | Download | 877380cc…cb12dd |
| 0.10.6 | Cached · Upstream SHA-256 matched | Download | c37896d1…6e0001 |
| 0.10.7 | Cached · Upstream SHA-256 matched | Download | 728d0269…86aaec |
| 0.10.8 | Cached · Upstream SHA-256 matched | Download | 5970ce45…6d7124 |
| 0.10.9 | Cached · Upstream SHA-256 matched | Download | 6f5f2efb…21bf42 |
| 0.11.0 | Cached · Upstream SHA-256 matched | Download | 78de0f52…a241a1 |
| 0.11.1 | Cached · Upstream SHA-256 matched | Download | 6281be4c…ebfa5c |
| 0.11.2 | Cached · Upstream SHA-256 matched | Download | 4fd902ce…0aa891 |
| 0.11.3 | Cached · Upstream SHA-256 matched | Download | d631ee7f…1e42ad |
| 0.11.4 | Cached · Upstream SHA-256 matched | Download | ed4c3976…a49af7 |
| 0.11.5 | Cached · Upstream SHA-256 matched | Download | 7c0e29ad…604ddf |
| 0.11.6 | Cached · Upstream SHA-256 matched | Download | 43c39ebf…4fc7e8 |
| 0.11.7 | Cached · Upstream SHA-256 matched | Download | 80803ffa…8d0263 |
| 0.11.8 | Cached · Upstream SHA-256 matched | Download | 6a2d7d99…ee352b |
| 0.11.9 | Cached · Upstream SHA-256 matched | Download | 3d4d8c79…8c5292 |
| 0.12.0 | Cached · Upstream SHA-256 matched | Download | 512f4814…ebb3dc |
| 0.12.1 | Cached · Upstream SHA-256 matched | Download | 0bb8d7d5…4c92d5 |
Dependencies
browser "any"