URLDispatcher 2.1

This library is an event dispatcher with a light URL base.
The size of the file is 8KB very lighter.



Details

Author
Noritaka Horio
Current version
2.1
GitHub
holyshared/URLDispatcher
Downloads
2718
Category
Utilities
Tags
Report
GitHub Issues

Releases


Dependencies

  • _self_/_current_:
    • Core/Array
    • Core/Type
    • Core/Class
    • URLDispatcher/URLDispatcher
    • Core/Object
    • URLDispatcher/URLDispatcher.Handler
    • Core/String
    • URLDispatcher/URLDispatcher.Route
    • Core/Events
    • Core/Options
    • URLDispatcher/URLDispatcher.Context
    • URLDispatcher/URLDispatcher.Resource
    • URLDispatcher/URLDispatcher.Router
    • URLDispatcher/URLDispatcher.HandlerManager
    • Core/Function

How to use

1. The event handler is registered to the dispatcher.

The event handler is registered to the dispatcher.
The event handler can specify the function or the object.

javascript

var dispatcher = new URLDispatcher();
dispatcher.addRoute('^/foo/$', function(context){
    //do something
});

or

var eventHandler = {
    //It is executed before invoke is called.
    beforeDispatch: function(context){
        //do something
    },

    execute: function(context){
        //do something
    },

    //After invoke is called, it is executed. 
    afterDispatch: function(context){
        //do something
    }
};

var dispatcher = new URLDispatcher();
dispatcher.addRoute('^/foo/$', eventHandler);

2. The event is executed.

The event is executed according to arbitrary timing. The data to be handed over to URL and the event handler is specified for the dispatch method.

The specified data can be referred to in the values property of argument context object of the event handler,
and the content that matches to the pattern of URL can be referred to in the params property of the context object.

javascript

var dispatcher = new URLDispatcher();
dispatcher.addRoute('^/foo/:page', function(context){

    var id = context.getArg('id');
    var page = context.getParam('page');

    alert(page); //Alert 100
    alert(id); //Alert eventDispatcher

}, ['\\d+']);

dispatcher.dispatch('/foo/100', {
    id: 'eventDispatcher'
});

Required Libraries

Mootools Core

http://mootools.net/core/a2c956ca31acc228a3d0294f4b035d9a


Building Urldispatcher

To do the build, the following command is specified by the packager.

Mootools

packager build Core/Type Core/Object Core/String Core/Function Core/Class +use-only Core -blocks 1.2compat

URLDispatcher

packager build URLDispatcher/* +use-only URLDispatcher


Discuss

A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.

Found a bug in this plugin? Please report it this repository's Github Issues.

blog comments powered by Disqus