W3cubDocs

/Dojo

dojo/AdapterRegistry

Summary

A registry to make contextual calling/searching easier.

Objects of this class keep list of arrays in the form [name, check, wrap, directReturn] that are used to determine what the contextual result of a set of checked arguments is. All check/wrap functions in this registry should be of the same arity.

Usage

AdapterRegistry(returnWrappers);
Parameter Type Description
returnWrappers Boolean
Optional

See the dojo/AdapterRegistry reference documentation for more information.

Examples

Example 1

// create a new registry
require(["dojo/AdapterRegistry"],
function(AdapterRegistry){
    var reg = new AdapterRegistry();
    reg.register("handleString",
        function(str){
            return typeof val == "string"
        },
        function(str){
            // do something with the string here
        }
    );
    reg.register("handleArr",
        dojo.isArray,
        function(arr){
            // do something with the array here
        }
    );

    // now we can pass reg.match() *either* an array or a string and
    // the value we pass will get handled by the right function
    reg.match("someValue"); // will call the first function
    reg.match(["someValue"]); // will call the second
});

Properties

pairs

Defined by: dojo/AdapterRegistry

returnWrappers

Defined by: dojo/AdapterRegistry

Methods

match()

Defined by dojo/AdapterRegistry

Find an adapter for the given arguments. If no suitable adapter is found, throws an exception. match() accepts any number of arguments, all of which are passed to all matching functions from the registered pairs.

Returns: undefined

register(name,check,wrap,directReturn,override)

Defined by dojo/AdapterRegistry

register a check function to determine if the wrap function or object gets selected

Parameter Type Description
name String

a way to identify this matcher.

check Function

a function that arguments are passed to from the adapter's match() function. The check function should return true if the given arguments are appropriate for the wrap function.

wrap Function
directReturn Boolean
Optional

If directReturn is true, the value passed in for wrap will be returned instead of being called. Alternately, the AdapterRegistry can be set globally to "return not call" using the returnWrappers property. Either way, this behavior allows the registry to act as a "search" function instead of a function interception library.

override Boolean
Optional

If override is given and true, the check function will be given highest priority. Otherwise, it will be the lowest priority adapter.

unregister(name)

Defined by dojo/AdapterRegistry

Remove a named adapter from the registry

Parameter Type Description
name String

The name of the adapter.

Returns: Boolean | boolean

Returns true if operation is successful. Returns false if operation fails.

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/AdapterRegistry.html