2.2.32 • Published 1 year ago

@kollorg/ducimus-accusamus-dolorem v2.2.32

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

GitHub version Coverage Status JavaScript Style Guide: Good Parts dependency status contributions welcome

What is it?

Library offers to create callback functions and connect it by unique id descriptor with the promise object.

How to use it?

There are couple options how to get it into your project.

  1. You using npm/yarn and you want to install it with it, so do npm i @kollorg/ducimus-accusamus-dolorem and then import it import c2p from "@kollorg/ducimus-accusamus-dolorem";,
  2. you typing vanilla js and you want to import it, <import src="https://raw.githubusercontent.com/domino2/@kollorg/ducimus-accusamus-dolorem/master/dist/umd.min.js" /> what will store the @kollorg/ducimus-accusamus-dolorem into window.c2p,
  3. you using umd modules in the browser, import * as c2p from "https://raw.githubusercontent.com/domino2/@kollorg/ducimus-accusamus-dolorem/master/dist/module.min.mjs";
  4. or you doing Deno application, import * as c2p from "https://raw.githubusercontent.com/domino2/@kollorg/ducimus-accusamus-dolorem/master/dist/module.min.mjs"; ,
  5. node.js application c2p = require('@kollorg/ducimus-accusamus-dolorem')

The github raw files cannot be used as I did above to import the library. For more details read this. In case you work in browser, store the dist file locally or on the server.

After that, just call successfn function to get success callback. failfn return fail callback.

c2p = require('@kollorg/ducimus-accusamus-dolorem')
function countIn(a, b, resultback) {
    resultback(a+b);
}

countIn(3, 4, c2p.successfn('id'))
c2p.when('id').then(console.log) // -> 7

Multiple arguments

When success or fail callback is called with object, simple value or array, those are available as usual in the promise function. Multiple arguments are wrapped into object, because resolve and reject functions pass only one argument.

c2p = require('@kollorg/ducimus-accusamus-dolorem')
function countIn(a, b, resultback) {
    resultback(a+b, a*b, a-b);
}

countIn(3, 4, c2p.successfn('id'))
c2p.when('id').then(console.log) // -> { '0': { '0': 7, '1': 12, '2': -1 }}

Real Life example - reading files

c2p = require('@kollorg/ducimus-accusamus-dolorem')
fs = require('fs')

// callback approach - probably better :-) because of passing multiple arguments
//fs.readFile('/etc/hosts', 'utf8', function (err,data) {
//    if (err) throw(err)
//    else console.log(data)
//})

// @kollorg/ducimus-accusamus-dolorem approach

fs.readFile('/etc/hosts', 'utf8', c2p.successfn('p-id-1'))

c2p.id('p-id-1').promise.then(function(args){

    let err = args[0]
    let data = args[1]

    if (err) throw(err)
    else console.log(data)
})

Nuance 1

c2p = require('@kollorg/ducimus-accusamus-dolorem') returning global object which could be used from any place and work with same promise as has been used on other place of project according to ID.

c3p = require('@kollorg/ducimus-accusamus-dolorem').build() on other side creating local object and cannot share promise with other parts of your project.

c2p.when('id').then(console.log)
c3p.when('id').then(console.log)

c2p.id('id').resolve(1)
// c2p.id('id').resolve(3) // -> it will throw an exception
c3p.id('id').resolve(2)
// c3p.id('id').resolve(4) // -> it will throw an exception

// output -> 1 and 2

Nuance 2 - multi-when

It is possible to wait for resolve of multiple promises.

function sum(a, b, cb) { cbk(a+b) }

c2p.when(['ab.2','ab.1','another']).then((a) => expect(a).to.eql([8,5,'test']))

sum(1, 4, c2p.successfn('ab.1'))
c2p.id('another').resolve('test')
sum(3, 5, c2p.successfn('ab.2'))

API

c2b: promiser object

  • function id(string): deferred object
  • function successfn(string): solve callback - pointing to resolve fn from deferred
  • function failfn(string): reject callback - pointing to reject fn from deferred
  • function when(string|string[]): thenable object
  • function build(): new promiser object

deferred object

  • funciton isPending(): true|false
  • function isSucceed(): true|false
  • function isFailed(): true|false
  • function isSameObjectAs(): true|false - test if two pointer referencing same object
  • function resolve(): void - it can pass multiple arguments, see note above
  • function reject(): void - it can pass multiple arguments, see note above
Array.prototype.flatten@@toStringTagECMAScript 5jestspringinputconsoleespreeextendobjectsimple cacheperformantcodescjknativeclienttypedoffsetObject.definePropertyopenercolourpushintrinsicgetoptpersistentbrowserspeedStyleSheetbluebirdESnextES2021findLastIndexconvertcompilerReactiveExtensionsanimationchineseimportexportcontainslistenerstypedarrayes6ESECMAScript 2016snsslicemochaframerescapearktypestyleguidecachecliprivateratelimitString.prototype.trimdeep-clonebreakconfigrouteObject.keysfindkey parprotovalueslastparserrecursivehardlinksdependency managerreduxmatchespyyamlECMAScript 7dataviewjsxproxyObject.ismulti-packageworkershimisvesteventDispatcherECMAScript 6hooksjQuerytoSortedargumentpreserve-symlinksnumberUnderscoreenvironmentsdeterministicstylesasciiArrayECMAScript 3RxsearchnodejsratezeroterminalchannelcolumnreadableminimalopensbuffersnodenopehookformenderPromiseinspectfsmkdirpttyurleventsvpcawaitforEachendpointposerequirecommanda11yinferenceES8protobufeslintconfigObject.entriesUint32Arrayxdg-openmetadatapicomatchnegative zerocomputed-typeschromeslotoutputcolorsES3oncechildupreact animationaccessorviewdirectoryreact-testing-libraryerrorlibphonenumbercloudwatchsymboldeleteflatMaphelperscolumnsparentES2018ES2023internalefficientarraybuffertostringtagfunction.lengthinvariantvalueoptimistpackagesstreamfastclonebytesortedlrugroupregexppromiseSetcloudformationmkdirsArray.prototype.filterquerystringfast-clonekeyscallbackrangeerrorObject.assignreact-hook-formruntimedomsharedarraybufferlocationes-shimsgetintrinsicuninstalltsavaassertselasticachetimeregularcharactersformsfullwidthes2015idletelephonetermcommandertyped arraygettervariablesfastwhatwgfetchparentsapiiterationidentifierspostcss-pluginmodulefind-uppatchvalidaterfc4122workflowlockfileloadingRegExp.prototype.flagsrgbrm -frAsyncIteratorsyntaxInt16Arraycss-in-jsArray.prototype.containssymbolsWeakSetcallbindcallboundtoolsfunctioncsswalkingmake dirArray.prototype.flatmimetypestexteditorcryptosetcall-bindrm -rffindupfastcopyrmregexhashstoragegatewayqueryArray.prototype.findLastIndexreduceisConcatSpreadable__proto__descriptorsgetkarmalook-uprandomInt8ArraycomparesimpledbwidthFloat64ArraymomentES2015CSSStyleDeclarationkey valuelinewrapwrapUint16Arrayes2018writableutilformatresolvestringsidethrottleSymbol.toStringTagreact-hooksemojiredux-toolkitphonewordwrapconcurrencyl10nexpressmobilees5util.inspectbindstreamsinstrumentationtypermdirqsTypedArrayfile cachegraphqlaccessibilitytoobjectsuperagentsetImmediateexecutablecloudtrailidkinesisjsdomstyletrimEndeslintpluginassignwriteStreampostcssboundpropponyfilleslint-plugintslibjsonfixed-width[[Prototype]]ec2ECMAScript 2018JSONwordbreakBigInt64ArrayString.prototype.matchAlldataViewstablefast-copyserializationgesturesmapreducepopmotiontrimStartrdscollection.es6spinnerscheme-validationlintsqsRegExp#flagsinbeanstalkdebugObject.values3dflagsreducerdefaulttapjapaneses3sortfigletextramodulesextensionpathcharsetYAMLieIterator256prettysesmkdirObject.fromEntriesweaksetloggervarsbatchgetOwnPropertyDescriptortypescolorexeWeakMapECMAScript 2020routingreuseformattingmakereact posecharacterlookconfigurableMapiterateflattenes2016circulareast-asian-widthimmutableworkspace:*datastructurehasOwnes8HyBiobjbannerECMAScript 2023descriptordeep-copyglobalebstestingprivate dataweakmapObjectdotenvES2019chaipropertiesBigUint64ArrayArrayBuffer#slicestylingpolyfilles2017dateMicrosoftECMAScript 2019coveragestructuredCloneECMAScript 2021Streamsmru_.extendstyled-componentsclass-validatordynamodbi18nstartqueue.envairbnblinkbddspawnyupimmerconsumelogdayjsjavascriptfile systemmime-dbInt32Arrayprefixutilitiesfull-widthastzodsharedregular expressionjasminegetPrototypeOfawesomesaucesequenceecmascriptwhichjoiremovebyteLengthassertFunction.prototype.nameECMAScript 2015shellES2020deepclonelimitsettingsautoscalingajvhigher-orderloggingObject.getPrototypeOfappcore-jsspectoolkitArray.prototype.findLastloadbalancingagentbundlerdropdescriptiontester0es-abstractObservableReflect.getPrototypeOfschematapeECMAScript 2022tc39cloneapolloelbArrayBufferpackage.jsonstreams2ownfromargumentsES2022difflaunchmimeeslintpromisesxtermcensorchromiumredactoptiontouchserializeenvoptimizerpruneES6languagepropertyio-tsArrayBuffer.prototype.slicedirlimitedregular expressionsprototypeawsglobwaapiSymbolxhrunicodedeepurlsflagprotocol-bufferscode pointsrobustthroatnamevalidationwgetparsingroute53setPrototypeOfstringifierdom-testing-libraryexecinstallernegativebundlingreal-timetypesaferapidcorehttpsjsonpathFloat32ArrayargspositiveestreeglacierenvironmentdebuggersameValueZeroequalityjsTypeBoxexpressiongdprrequestlengthfilterdataiconvpnpm9ES5shebangvalidarraysArray.prototype.flatMapstarterlazybusycollectionmonorepoRFC-6455schemetddhelperspinnersfunctionsES2016matchAllfastifyfunctionaltypeofgroupByajaxfilecall-bounddragdefinePropertyreactfullicucmdUint8ArrayfindLastcheck$.extendtypescriptwarningtoStringTagwaftoArraycommand-lineguidformstringifyargvincludesfolderasyncentriescallfast-deep-clonestdlibmovetakemergesetterredirectglobalsopenObservableses-shim APIWebSocketsperformanceeverynamesjshintsyntaxerrordeepcopypackage managerxdgmatchfpsistanbulcurlhttpreadablestreambyteOffsetReactiveXPusharrayreaduuidjson cachetypeerrorArray.prototype.includesconcatMapjsdiffwalkstatelesswaitcloudsearchpackagenpmparseRxJSsymlinksymlinksbrowserslistprogresshasOwnPropertyautoprefixercreateutilitycopyES2017genericsomitCSSyamlduplexinternal slotmapwebsitefast-deep-copytrimRightcloudfronttypanionECMAScript 2017browserlistURLSearchParams
2.1.27

1 year ago

2.0.15

1 year ago

2.0.16

1 year ago

2.0.13

1 year ago

2.1.26

1 year ago

2.0.14

1 year ago

2.2.31

1 year ago

2.2.32

1 year ago

2.2.30

1 year ago

2.0.19

1 year ago

2.0.17

1 year ago

2.0.18

1 year ago

2.2.28

1 year ago

2.0.26

1 year ago

2.2.29

1 year ago

2.0.24

1 year ago

2.2.27

1 year ago

2.0.25

1 year ago

2.0.22

1 year ago

2.0.23

1 year ago

2.0.20

1 year ago

2.0.21

1 year ago

2.0.12

1 year ago

2.0.11

1 year ago

2.0.9

1 year ago

2.0.10

1 year ago

2.0.8

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago