{"id":21326223,"url":"https://github.com/masylum/backbone.middleware","last_synced_at":"2025-07-12T06:32:59.855Z","repository":{"id":7369338,"uuid":"8695330","full_name":"masylum/backbone.middleware","owner":"masylum","description":"Backbone.middleware","archived":false,"fork":false,"pushed_at":"2015-10-14T14:27:20.000Z","size":172,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-15T23:24:20.472Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/masylum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-11T02:40:13.000Z","updated_at":"2020-02-25T07:26:14.000Z","dependencies_parsed_at":"2022-09-15T03:30:31.442Z","dependency_job_id":null,"html_url":"https://github.com/masylum/backbone.middleware","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masylum%2Fbackbone.middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masylum%2Fbackbone.middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masylum%2Fbackbone.middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/masylum%2Fbackbone.middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/masylum","download_url":"https://codeload.github.com/masylum/backbone.middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225802658,"owners_count":17526452,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T21:08:50.263Z","updated_at":"2024-11-21T21:08:50.748Z","avatar_url":"https://github.com/masylum.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Backbone middleware\n\nRouters are fine, but sometime you need moar.\n\n## Usage\n\nBackbone middleware is very easy to use.\nJust pass around data on the `this` object, and use named\nfunctions to call `next` or `error` (sorry coffescript... no, not really).\n\n## API\n\nBackbone middleware chain functions that transport data with the `this` object.\nWith `fn.next()` you can call to the next middleware.\nWith `fn.error()` you stop your middleware chain and\ncalls `Backbone.Middleware.handleError` (left to you to implement).\n\n### Middleware\n\nComposes a set of middlewares and returns a function.\n\n```javascript\nvar middleware = Backbone.Middleware.middleware;\n\n  function authenticateMiddleware(user_id) {\n    if (user_id === 1) {\n      authenticateMiddleware.next();\n    } else {\n      $('body').html('\u003ch1\u003eAuthentication error!\u003c/h1\u003e');\n      authenticateMiddleware.error();\n    }\n  }\n\n  Controller.index = middleware(authenticateMiddleware, function (user_id) {\n    alert('Welcome! ' + user_id);\n  });\n```\n\n### Params\n\nMiddleware to extract the parameters and populate a `this.params` objects.\nThis should be built-in Backbone!\n\n```javascript\nvar middleware = Backbone.Middleware.middleware;\n  , params = Backbone.Middleware.params;\n\n  function authenticateMiddleware() {\n    if (this.params.user_id === 1) {\n      authenticateMiddleware.next();\n    } else {\n      $('body').html('\u003ch1\u003eAuthentication error!\u003c/h1\u003e');\n      authenticateMiddleware.error();\n    }\n  }\n\n  Controller.index = middleware(params(['user_id']), authenticateMiddleware, function () {\n    alert('Welcome! ' + this.params.user_id);\n  });\n```\n\n### Stack\n\nSimilar to `middleware` but accepts arrays of functions.\nReally useful for building your middleware stacks to be reused.\n\n```javascript\nvar middleware = Backbone.Middleware.middleware;\n  , params = Backbone.Middleware.params;\n\n  function authenticateMiddleware() {\n    if (this.params.user_id === 1) {\n      authenticateMiddleware.next();\n    } else {\n      $('body').html('\u003ch1\u003eAuthentication error!\u003c/h1\u003e');\n      authenticateMiddleware.error();\n    }\n  }\n\n  function authenticateStack() {\n    var args = _.toArray(arguments);\n\n    return BackboneMiddleware.stack(\n      BackboneMiddleware.params.apply(this, args[0])\n    , authenticateMiddleware\n    , args.slice(1)\n    );\n  }\n\n  Controller.index = authenticateStack(['user_id'], function () {\n    alert('Welcome! ' + this.params.user_id);\n  });\n```\n\n## Tests\n\nNot yet, sorry\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2013 Pau Ramon \u003cmasylum@gmail.com\u003e\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasylum%2Fbackbone.middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmasylum%2Fbackbone.middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmasylum%2Fbackbone.middleware/lists"}