{"_id":"gbL-jsMop","_rev":"33-f91d9e312cc125d51fc4cf374906f71c","name":"gbL-jsMop","description":"Message passing library","dist-tags":{"latest":"0.14.4"},"versions":{"0.9.3":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.9.3","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"_id":"gbL-jsMop@0.9.3","_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"fa670985c87a6d9eb98f42a0afefefc04f7152cb","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.9.3.tgz","integrity":"sha512-8Jrt6HsGRuUOjGWxGg0eAOlUlOYuyZzB3nhPSVKX1DlwfQwkeclSkBDCjH6rB4UDTvyFlsI7H9qydlunKEh8iw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDb2MLNgHdrXpzdhZSaXhAXeXgUhnCcln1AF78wfsVYaAIgFD44IgmpKGsBuWg75CS4l/UX2cV0O2uD0ymXjNPwAYo="}]},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.9.5":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.9.5","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"_id":"gbL-jsMop@0.9.5","_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"6353711a8dd30fb700c13fffef16b8928447f7e4","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.9.5.tgz","integrity":"sha512-2iZpzJWGc90WuOpvThHOO8Bxbe4K1Y13TOKommpkHC56h6kiDelXBqDKuGpCjK8BPCldBw+r4xq6KhlT7cEW3A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQChz3s8twI+fjfogWe8pl7rWFDhrr4NxrNmDAoxABT97wIgCaJOFfW8uz2uOF0fzuwP0HMwf/KWF4UifeqllpX+9us="}]},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.9.6":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.9.6","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"_id":"gbL-jsMop@0.9.6","_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"5639c2c7ea0bbab6cb9f9863e37c0ffc7e3d68a1","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.9.6.tgz","integrity":"sha512-v52gn6QlviOYEGEcoTsx12v++cNRwoW4Sg+BycuS3dR/sh0jhVS+sqZ0k6cf+8pMD1L5iaL42M6OKanCv/SHGQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICZHc/CxQebeAYHDMWCFhohXtRDmQhP0qZwvKXdK54j6AiBOsT5xqlKXchddmHoAlFgkTKSUkTuQvz0pZQ4sh2hzDQ=="}]},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.9.7":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.9.7","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"_id":"gbL-jsMop@0.9.7","_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"4d0b33cdeb65f8ddbb321e8d78e24fd386810b94","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.9.7.tgz","integrity":"sha512-xB+f9bJr1Byx0L3se+N7upw50r6+dJhO/x0UbRPfp/NIiW8+HaruIsShEA/32gYoMLDllQOEtskEsNuVgPC3Qg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCMjJPRMpjWPxlL8L3XpEV7NpZO4878IvRV8zOSPMdqZgIgRd40IGVHRbNaVAyr9hTdoRD71cNH3ju7qLLRZqP5zGA="}]},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.10.0":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.10.0","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"_id":"gbL-jsMop@0.10.0","_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"5ec1fa9a5e386f67195dd693aa07e36f40313a7c","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.10.0.tgz","integrity":"sha512-6vg3V+VNars6HF+BhNKdRkP9cZy2jtHpd135R9+/qdSwIaKu1fY82vPOdf9aOSQn0yTwvLB7SCAmJCgjQ41T7w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDUmKx0CvwtX31d+4LYjVh9H47j6evAy06OnA9exXmchQIhAM3E2Mjm3DFZkrZ4JHnxWTSjUx3kG41IZDCAGEey6eXS"}]},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.11.0":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.11.0","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"_id":"gbL-jsMop@0.11.0","_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"5686a1b3dea18fa46402f185abbe5a970060951b","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.11.0.tgz","integrity":"sha512-rlBnaqZfkpZMVS0IuXl9eF6Z78IhpKZ3VDYyW8qZYozbF8gLnFxArWA7tgEvqb1S17mZ2DNXj0dsOvPreNmEeA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCglSyXYAbQZXPSPju3JVD90uL+N9JFn5zXGbiT4/AnbwIgQmwTjdd2J2qV2U4JkRddcuavtWG3Juiwj3631Aogb5s="}]},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.12.0":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.12.0","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"_id":"gbL-jsMop@0.12.0","_engineSupported":true,"_npmVersion":"1.1.9","_nodeVersion":"v0.6.13","_defaultsLoaded":true,"dist":{"shasum":"1f3fd4169d00968c4bd9c2de2281490db146aa72","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.12.0.tgz","integrity":"sha512-nzcpVNGMqwsTWSivSEIMpm1fO4SoAcd4+Qcgjy18rU4nn0DCtGyzxTMF3Dnvd/aGEwsArpRclyLNrr1MbuNtyA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG7wfHgfgYz6U2UOvbzgZpY6D7yB4xUgIO8ymfGU9CM7AiEAzt+o+XPevKjfRn+hIiZuFH8kqA4dTI3BsHWnRY1PioY="}]},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.13.0":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.13.0","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"\n# gbL.jsMop\n\n## Preamble\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Sending messages\nWhen I think about OO, I think of objects like individual biological cells, which can communicate by emitting messages which can be absorbed by nearby cells.\n\nThis is a bit different than the normal paradigm in most C-like languages - javascript, C#, Java etc.\n\nWhere, in normal javascript, I would write\n\n    listView.render(viewData);\n    \nI would really rather do something like\n\n    send.renderViewList(viewData);\n\nand have this message picked up by the appropriate view. It means I don't have to retain a reference to the receiving object(s), and it fits the biological model more closely.\n\nIn the recipient, I would like to specify messages I will receive. Something like\n\n    receive.renderView(viewData);\n    \nHowever, this kind of paradigm doesn't really exist at a native level in javascript. You can simulate this kind of thing in many ways, including things like the Observer pattern, Bus architectures and Blackboard patterns/architectures.\n\nI wanted something simple, flexible, but also something that worked with a minimum of effort. So I write the gbL.jsMop script as a workaround.\n\n## tl;dr / Show me the money\n\nHere we create a <code>mop</code> object, and create+register a <code>Controller</code> object and two <code>View</code> objects. Then I send a \"show names\" message through the <code>mop</code> which is received by the <code>Controller</code>. The <code>Controller</code> then processes the data into a view model and sends a \"render view list\" message. The \"List\" <code>View</code> object receives this message and renders itself using the view model sent by the <code>Controller</code>.\n\n    var mop = new gbL.jsMop()\n    \t.register(new Controller(), \"List controller\")\n    \t.register(new View(\"List\"), \"List view\")\n    \t.register(new View(\"AnOther\"), \"AnOther view\")\n    \t;\n    \t\n\tvar data = [\n\t\t{ name: \"Jessie\" },\n\t\t{ name: \"Imran\" }\n\t];\n\t\n\t/* \n        When the \"show names\" message is sent, the controller would \n\t    receive it, because it says \"I.receive.showNames\"\n\t*/ \n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n    \n\tfunction View(viewName) {\n\t\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.renderView = function(viewData) {\n\t\t\trenderSelf(viewData);\n\t\t}\n\t\t// ... but only messages ending with my name\n\t\tI.receive.renderView.filter = function(topics, data) {\n\t\t\treturn topics[topics.length] === viewName;\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction renderSelf(viewData) {\n\t\t\t. . .\n\t\t}\n\t}\n \n## Modular design\nI also want to be able to divide my code up into dependency-free units. I don't want my constructor functions for each class of object to reference each other at design time any more than I want my objects to reference each other at run-time….\n\nSo I added the bootstrap pattern. For example:\n\nmain.js\n\n\tvar mop = new gbL.jsMop().boot({\n\t\t\"View factory\" : require(\"./viewFactory\"),\n\t\t\"List controller\" : require(\"./listController\"),\n\t});\n\t\nviewFactory.js\n\n    module.exports.init = function(mop) {\n    \tmop.register(new ViewFactory(mop), \"View factory\");\n    };\n    \n\tfunction ViewFactory(mop) {\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.buildView = function(viewName) {\n\t\t\tvar view = new View(viewName);\n\t\t\tmop.register(view, viewName + \" view\");\n\t\t};\n\t\t\n\t\treturn I;\n\t}\n\n\tfunction View(viewName) {\n\t\t. . .\n\t}\n\nlistController.js\n\n\tmodule.exports.init = function(mop) {\t\n\t\tmop.register(new Controller(), \"List controller\");\n\t}\n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.buildView = function(){};\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tensureListView();\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction ensureListView() {\n\t\t\tI.send.buildView(\"List\");\n\t\t\tensureListView = function() { }; // naughty\n\t\t}\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n\n# Up-to-date example (if below==tl;dr)\n\nThe constructor is divided into two sections:\n\n1. Define the messages received and/or sent\n2. Define business logic in functions\n \nBelow the sections are divided by the line \"return I;\"\n\n    function Controller() {\n    \n\t\t// I will both send and receive messages\n\t\tvar I = { receive: {}, send: {} };\n\t\t\n\t\t// the \"render view\" message - intended for registered Views to receive\n\t\tI.send.renderView = function(viewName, data, res){};\n\t\t\n\t\t// the \"model update request\" message - intended for the model\n\t\tI.send.modelUpdateRequest = function(command){};\n\t\t\n\t\t// the router creates this message on receiving GET /documentList\n\t\tI.receive.GETdocumentList = function(req, res) {\n        \tlistDocuments(function(data) {\n        \t\tI.send.renderView(\"document-list\", data, res);\n        \t});\n        };\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction listDocuments(callback) {\n\t\t\t// send a \"list-documents\" command to the model\n\t\t\tI.send.modelUpdateRequest(\"list-documents\", function(domain) {\n\t\t\t\tcallback(domain.documents);\n\t\t\t});\n\t\t}\n    }\n\nAn object of this type can be registered as normal:\n\n    var mop = new gbL.jsMop();\n    mop.register(new ns.Controller(), \"Documents controller\");\n    mop.register(new ns.ListDocumentsView(), \"List documents view\");\n    mop.reigster(new ns.DomainCommandProcessor(), \"Command interface for the domain\");\n\nor, using the bootstrap pattern (see below):\n\n    new gbL.jsMop().boot({\n        \"controller\" : require(\"./controllers/Controller.js\"),\n        \"documents view\" : require(\"./views/ListDocuments.js\"),\n        \"domain command processor\" : require(\"./model/CommandProcessor.js\")\n    });\n    \nFor this to work, Controller.js would have to include the bootstrapping code which allows modules to initialise themselves and register objects. It would end up looking something like:\n\n    module.exports.bootstrap = function(mop) {\n    \tmop.register(new Controller(), \"Documents controller\");\n    };\n\n\tfunction Controller() {\n\t\t. . . code (as above) goes here . . .\n\t}\n\n\n# tl;dr\n\n### No, really - I mean it. tl;dr\n\n# Version specific notes\nUnless otherwise indicated, the material in the Pervious Versions section still applies\n\n## New in version 0.9.7\n\nTuesday, 20 November 2012\nVersion 0.9.7\n\n### New pattern of registering receive and send messages\nThe principle change in this version is a new facility to receive and send which allows a slightly cleaner syntax. It also encourages you to declare the messages you will send ahead-of-time.\n\n#### \"Interface\" concept\nObjects can now simulate declaration of an interface using the revealing module pattern. Often you will see this:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\t// public members here\n\t\t};\n    \n\t\treturn I;\n\t\t\n\t\t// private functions here\n\t\t\n    }\n    \n#### Receiving and sending\nAn object wishing to receive and/or send should now declare a receive and or send attribute:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\treceive: {\n\t\t\t\t// messages to receive here\n\t\t\t},\n\t\t\tsend: {\n\t\t\t\t//messages to send here\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\t// private functions here\n    }\n\n#### No more underscoring\nMessages in these receive and send attributes should be declared using simple camel casing\n\ne.g.\n\n    this.receive_add_commit_message = function(stuff) {\n    \t// do something with the stuff received\n    };\n\nshould now be written as\n\n\tthis.receive.addCommitMessage = function(stuff) {\n\t\t// do something with the stuff received\n\t};\n\n#### Collect senders at the top\nTo make debugging easier, declare your senders at the top as (usually) empty functions:\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff){};\n    \nafter the object is registered, will send a message with subject \"add commit message\". The inclusion of parameters in the empty function definition is useful as documentation. In addition, you can add your own action which will be called after the message is sent.\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff) {\n    \tlog(\"A commit message has been sent\");\n    };\n    \n## Base Version - 0.9.3\nSunday, 10 June 2012  \nVersion 0.9.3  \n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL-jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = function(initMop) {\n\t\t\tmop = initMop;\n\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL-jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: function(jsMop) {\n\t\t\t\tmop = jsMop;\n\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, toGet)\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","readmeFilename":"README.md","_id":"gbL-jsMop@0.13.0","dist":{"shasum":"b8a2aaec557a14ca5551b4a45f9d8c65d3869b07","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.13.0.tgz","integrity":"sha512-4skq+k8nh+Zpe6X2Sjui3NvWkx6o5uluwVHS+IqsZzB7LHq61AuUA0PxqrtMsJv4EqwkW2zJGQVTCuq0YAxXNA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEAcZSSOslDW2f/41SYeuN19u9wx0lLY7omsV2xDtw8RAiEA/ELlzrJRbmAcbDI42uqRorsTTMV8x4yCqwEiIOTymbw="}]},"_npmVersion":"1.1.69","_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.13.1":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.13.1","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"\n# gbL.jsMop\n\n## Preamble\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Sending messages\nWhen I think about OO, I think of objects like individual biological cells, which can communicate by emitting messages which can be absorbed by nearby cells.\n\nThis is a bit different than the normal paradigm in most C-like languages - javascript, C#, Java etc.\n\nWhere, in normal javascript, I would write\n\n    listView.render(viewData);\n    \nI would really rather do something like\n\n    send.renderViewList(viewData);\n\nand have this message picked up by the appropriate view. It means I don't have to retain a reference to the receiving object(s), and it fits the biological model more closely.\n\nIn the recipient, I would like to specify messages I will receive. Something like\n\n    receive.renderView(viewData);\n    \nHowever, this kind of paradigm doesn't really exist at a native level in javascript. You can simulate this kind of thing in many ways, including things like the Observer pattern, Bus architectures and Blackboard patterns/architectures.\n\nI wanted something simple, flexible, but also something that worked with a minimum of effort. So I write the gbL.jsMop script as a workaround.\n\n## tl;dr / Show me the money\n\nHere we create a <code>mop</code> object, and create+register a <code>Controller</code> object and two <code>View</code> objects. Then I send a \"show names\" message through the <code>mop</code> which is received by the <code>Controller</code>. The <code>Controller</code> then processes the data into a view model and sends a \"render view list\" message. The \"List\" <code>View</code> object receives this message and renders itself using the view model sent by the <code>Controller</code>.\n\n    var mop = new gbL.jsMop()\n    \t.register(new Controller(), \"List controller\")\n    \t.register(new View(\"List\"), \"List view\")\n    \t.register(new View(\"AnOther\"), \"AnOther view\")\n    \t;\n    \t\n\tvar data = [\n\t\t{ name: \"Jessie\" },\n\t\t{ name: \"Imran\" }\n\t];\n\t\n\t/* \n        When the \"show names\" message is sent, the controller would \n\t    receive it, because it says \"I.receive.showNames\"\n\t*/ \n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n    \n\tfunction View(viewName) {\n\t\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.renderView = function(viewData) {\n\t\t\trenderSelf(viewData);\n\t\t}\n\t\t// ... but only messages ending with my name\n\t\tI.receive.renderView.filter = function(topics, data) {\n\t\t\treturn topics[topics.length] === viewName;\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction renderSelf(viewData) {\n\t\t\t. . .\n\t\t}\n\t}\n \n## Modular design\nI also want to be able to divide my code up into dependency-free units. I don't want my constructor functions for each class of object to reference each other at design time any more than I want my objects to reference each other at run-time….\n\nSo I added the bootstrap pattern. For example:\n\nmain.js\n\n\tvar mop = new gbL.jsMop().boot({\n\t\t\"View factory\" : require(\"./viewFactory\"),\n\t\t\"List controller\" : require(\"./listController\"),\n\t});\n\t\nviewFactory.js\n\n    module.exports.init = function(mop) {\n    \tmop.register(new ViewFactory(mop), \"View factory\");\n    };\n    \n\tfunction ViewFactory(mop) {\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.buildView = function(viewName) {\n\t\t\tvar view = new View(viewName);\n\t\t\tmop.register(view, viewName + \" view\");\n\t\t};\n\t\t\n\t\treturn I;\n\t}\n\n\tfunction View(viewName) {\n\t\t. . .\n\t}\n\nlistController.js\n\n\tmodule.exports.init = function(mop) {\t\n\t\tmop.register(new Controller(), \"List controller\");\n\t}\n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.buildView = function(){};\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tensureListView();\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction ensureListView() {\n\t\t\tI.send.buildView(\"List\");\n\t\t\tensureListView = function() { }; // naughty\n\t\t}\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n\n# Up-to-date example (if below==tl;dr)\n\nThe constructor is divided into two sections:\n\n1. Define the messages received and/or sent\n2. Define business logic in functions\n \nBelow the sections are divided by the line \"return I;\"\n\n    function Controller() {\n    \n\t\t// I will both send and receive messages\n\t\tvar I = { receive: {}, send: {} };\n\t\t\n\t\t// the \"render view\" message - intended for registered Views to receive\n\t\tI.send.renderView = function(viewName, data, res){};\n\t\t\n\t\t// the \"model update request\" message - intended for the model\n\t\tI.send.modelUpdateRequest = function(command){};\n\t\t\n\t\t// the router creates this message on receiving GET /documentList\n\t\tI.receive.GETdocumentList = function(req, res) {\n        \tlistDocuments(function(data) {\n        \t\tI.send.renderView(\"document-list\", data, res);\n        \t});\n        };\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction listDocuments(callback) {\n\t\t\t// send a \"list-documents\" command to the model\n\t\t\tI.send.modelUpdateRequest(\"list-documents\", function(domain) {\n\t\t\t\tcallback(domain.documents);\n\t\t\t});\n\t\t}\n    }\n\nAn object of this type can be registered as normal:\n\n    var mop = new gbL.jsMop();\n    mop.register(new ns.Controller(), \"Documents controller\");\n    mop.register(new ns.ListDocumentsView(), \"List documents view\");\n    mop.reigster(new ns.DomainCommandProcessor(), \"Command interface for the domain\");\n\nor, using the bootstrap pattern (see below):\n\n    new gbL.jsMop().boot({\n        \"controller\" : require(\"./controllers/Controller.js\"),\n        \"documents view\" : require(\"./views/ListDocuments.js\"),\n        \"domain command processor\" : require(\"./model/CommandProcessor.js\")\n    });\n    \nFor this to work, Controller.js would have to include the bootstrapping code which allows modules to initialise themselves and register objects. It would end up looking something like:\n\n    module.exports.bootstrap = function(mop) {\n    \tmop.register(new Controller(), \"Documents controller\");\n    };\n\n\tfunction Controller() {\n\t\t. . . code (as above) goes here . . .\n\t}\n\n\n# tl;dr\n\n### No, really - I mean it. tl;dr\n\n# Version specific notes\nUnless otherwise indicated, the material in the Pervious Versions section still applies\n\n## New in version 0.9.7\n\nTuesday, 20 November 2012\nVersion 0.9.7\n\n### New pattern of registering receive and send messages\nThe principle change in this version is a new facility to receive and send which allows a slightly cleaner syntax. It also encourages you to declare the messages you will send ahead-of-time.\n\n#### \"Interface\" concept\nObjects can now simulate declaration of an interface using the revealing module pattern. Often you will see this:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\t// public members here\n\t\t};\n    \n\t\treturn I;\n\t\t\n\t\t// private functions here\n\t\t\n    }\n    \n#### Receiving and sending\nAn object wishing to receive and/or send should now declare a receive and or send attribute:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\treceive: {\n\t\t\t\t// messages to receive here\n\t\t\t},\n\t\t\tsend: {\n\t\t\t\t//messages to send here\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\t// private functions here\n    }\n\n#### No more underscoring\nMessages in these receive and send attributes should be declared using simple camel casing\n\ne.g.\n\n    this.receive_add_commit_message = function(stuff) {\n    \t// do something with the stuff received\n    };\n\nshould now be written as\n\n\tthis.receive.addCommitMessage = function(stuff) {\n\t\t// do something with the stuff received\n\t};\n\n#### Collect senders at the top\nTo make debugging easier, declare your senders at the top as (usually) empty functions:\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff){};\n    \nafter the object is registered, will send a message with subject \"add commit message\". The inclusion of parameters in the empty function definition is useful as documentation. In addition, you can add your own action which will be called after the message is sent.\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff) {\n    \tlog(\"A commit message has been sent\");\n    };\n    \n## Base Version - 0.9.3\nSunday, 10 June 2012  \nVersion 0.9.3  \n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL-jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = function(initMop) {\n\t\t\tmop = initMop;\n\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL-jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: function(jsMop) {\n\t\t\t\tmop = jsMop;\n\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, toGet)\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","readmeFilename":"README.md","_id":"gbL-jsMop@0.13.1","dist":{"shasum":"986e129da4a5482137397b3f31f646944f1601c6","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.13.1.tgz","integrity":"sha512-9y6krxbOvBOp8t8okILTkx/fOUibUwQm1qPTlCBjtfeyDT9VAzSEXM70LrLO/vsABDH4yeK8WbsPNVfXEywVew==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCWlpuyB9lrrUDyN0mIIwEvXjkDdK0rMmhrC+UzW3fuAAIhANF0mmbr0RJYPnbo046XjdbpN3Xr+p6cwE3Jw/vzCNRx"}]},"_npmVersion":"1.1.69","_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.13.2":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.13.2","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"\n# gbL.jsMop\n\n## Preamble\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Sending messages\nWhen I think about OO, I think of objects like individual biological cells, which can communicate by emitting messages which can be absorbed by nearby cells.\n\nThis is a bit different than the normal paradigm in most C-like languages - javascript, C#, Java etc.\n\nWhere, in normal javascript, I would write\n\n    listView.render(viewData);\n    \nI would really rather do something like\n\n    send.renderViewList(viewData);\n\nand have this message picked up by the appropriate view. It means I don't have to retain a reference to the receiving object(s), and it fits the biological model more closely.\n\nIn the recipient, I would like to specify messages I will receive. Something like\n\n    receive.renderView(viewData);\n    \nHowever, this kind of paradigm doesn't really exist at a native level in javascript. You can simulate this kind of thing in many ways, including things like the Observer pattern, Bus architectures and Blackboard patterns/architectures.\n\nI wanted something simple, flexible, but also something that worked with a minimum of effort. So I write the gbL.jsMop script as a workaround.\n\n## tl;dr / Show me the money\n\nHere we create a <code>mop</code> object, and create+register a <code>Controller</code> object and two <code>View</code> objects. Then I send a \"show names\" message through the <code>mop</code> which is received by the <code>Controller</code>. The <code>Controller</code> then processes the data into a view model and sends a \"render view list\" message. The \"List\" <code>View</code> object receives this message and renders itself using the view model sent by the <code>Controller</code>.\n\n    var mop = new gbL.jsMop()\n    \t.register(new Controller(), \"List controller\")\n    \t.register(new View(\"List\"), \"List view\")\n    \t.register(new View(\"AnOther\"), \"AnOther view\")\n    \t;\n    \t\n\tvar data = [\n\t\t{ name: \"Jessie\" },\n\t\t{ name: \"Imran\" }\n\t];\n\t\n\t/* \n        When the \"show names\" message is sent, the controller would \n\t    receive it, because it says \"I.receive.showNames\"\n\t*/ \n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n    \n\tfunction View(viewName) {\n\t\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.renderView = function(viewData) {\n\t\t\trenderSelf(viewData);\n\t\t}\n\t\t// ... but only messages ending with my name\n\t\tI.receive.renderView.filter = function(topics, data) {\n\t\t\treturn topics[topics.length] === viewName;\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction renderSelf(viewData) {\n\t\t\t. . .\n\t\t}\n\t}\n \n## Modular design\nI also want to be able to divide my code up into dependency-free units. I don't want my constructor functions for each class of object to reference each other at design time any more than I want my objects to reference each other at run-time….\n\nSo I added the bootstrap pattern. For example:\n\nmain.js\n\n\tvar mop = new gbL.jsMop().boot({\n\t\t\"View factory\" : require(\"./viewFactory\"),\n\t\t\"List controller\" : require(\"./listController\"),\n\t});\n\t\nviewFactory.js\n\n    module.exports.init = function(mop) {\n    \tmop.register(new ViewFactory(mop), \"View factory\");\n    };\n    \n\tfunction ViewFactory(mop) {\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.buildView = function(viewName) {\n\t\t\tvar view = new View(viewName);\n\t\t\tmop.register(view, viewName + \" view\");\n\t\t};\n\t\t\n\t\treturn I;\n\t}\n\n\tfunction View(viewName) {\n\t\t. . .\n\t}\n\nlistController.js\n\n\tmodule.exports.init = function(mop) {\t\n\t\tmop.register(new Controller(), \"List controller\");\n\t}\n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.buildView = function(){};\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tensureListView();\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction ensureListView() {\n\t\t\tI.send.buildView(\"List\");\n\t\t\tensureListView = function() { }; // naughty\n\t\t}\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n\n# Up-to-date example (if below==tl;dr)\n\nThe constructor is divided into two sections:\n\n1. Define the messages received and/or sent\n2. Define business logic in functions\n \nBelow the sections are divided by the line \"return I;\"\n\n    function Controller() {\n    \n\t\t// I will both send and receive messages\n\t\tvar I = { receive: {}, send: {} };\n\t\t\n\t\t// the \"render view\" message - intended for registered Views to receive\n\t\tI.send.renderView = function(viewName, data, res){};\n\t\t\n\t\t// the \"model update request\" message - intended for the model\n\t\tI.send.modelUpdateRequest = function(command){};\n\t\t\n\t\t// the router creates this message on receiving GET /documentList\n\t\tI.receive.GETdocumentList = function(req, res) {\n        \tlistDocuments(function(data) {\n        \t\tI.send.renderView(\"document-list\", data, res);\n        \t});\n        };\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction listDocuments(callback) {\n\t\t\t// send a \"list-documents\" command to the model\n\t\t\tI.send.modelUpdateRequest(\"list-documents\", function(domain) {\n\t\t\t\tcallback(domain.documents);\n\t\t\t});\n\t\t}\n    }\n\nAn object of this type can be registered as normal:\n\n    var mop = new gbL.jsMop();\n    mop.register(new ns.Controller(), \"Documents controller\");\n    mop.register(new ns.ListDocumentsView(), \"List documents view\");\n    mop.reigster(new ns.DomainCommandProcessor(), \"Command interface for the domain\");\n\nor, using the bootstrap pattern (see below):\n\n    new gbL.jsMop().boot({\n        \"controller\" : require(\"./controllers/Controller.js\"),\n        \"documents view\" : require(\"./views/ListDocuments.js\"),\n        \"domain command processor\" : require(\"./model/CommandProcessor.js\")\n    });\n    \nFor this to work, Controller.js would have to include the bootstrapping code which allows modules to initialise themselves and register objects. It would end up looking something like:\n\n    module.exports.bootstrap = function(mop) {\n    \tmop.register(new Controller(), \"Documents controller\");\n    };\n\n\tfunction Controller() {\n\t\t. . . code (as above) goes here . . .\n\t}\n\n\n# tl;dr\n\n### No, really - I mean it. tl;dr\n\n# Version specific notes\nUnless otherwise indicated, the material in the Pervious Versions section still applies\n\n## New in version 0.9.7\n\nTuesday, 20 November 2012\nVersion 0.9.7\n\n### New pattern of registering receive and send messages\nThe principle change in this version is a new facility to receive and send which allows a slightly cleaner syntax. It also encourages you to declare the messages you will send ahead-of-time.\n\n#### \"Interface\" concept\nObjects can now simulate declaration of an interface using the revealing module pattern. Often you will see this:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\t// public members here\n\t\t};\n    \n\t\treturn I;\n\t\t\n\t\t// private functions here\n\t\t\n    }\n    \n#### Receiving and sending\nAn object wishing to receive and/or send should now declare a receive and or send attribute:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\treceive: {\n\t\t\t\t// messages to receive here\n\t\t\t},\n\t\t\tsend: {\n\t\t\t\t//messages to send here\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\t// private functions here\n    }\n\n#### No more underscoring\nMessages in these receive and send attributes should be declared using simple camel casing\n\ne.g.\n\n    this.receive_add_commit_message = function(stuff) {\n    \t// do something with the stuff received\n    };\n\nshould now be written as\n\n\tthis.receive.addCommitMessage = function(stuff) {\n\t\t// do something with the stuff received\n\t};\n\n#### Collect senders at the top\nTo make debugging easier, declare your senders at the top as (usually) empty functions:\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff){};\n    \nafter the object is registered, will send a message with subject \"add commit message\". The inclusion of parameters in the empty function definition is useful as documentation. In addition, you can add your own action which will be called after the message is sent.\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff) {\n    \tlog(\"A commit message has been sent\");\n    };\n    \n## Base Version - 0.9.3\nSunday, 10 June 2012  \nVersion 0.9.3  \n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL-jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = function(initMop) {\n\t\t\tmop = initMop;\n\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL-jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: function(jsMop) {\n\t\t\t\tmop = jsMop;\n\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, toGet)\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","readmeFilename":"README.md","_id":"gbL-jsMop@0.13.2","dist":{"shasum":"6513f27a3097156ad8021711696091d6105ecaea","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.13.2.tgz","integrity":"sha512-XyQ26vp8Lluh3lKCtnq22pbcchF1UZpvokhToZXCBdg5sffhPob7M3yRjkwVYp16TvpK1joJalaBfbIYr1OXKQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCTp2XqWaTFM7VHu/4OohU6C177iTloKxgKw36VN7Y1wQIhANsTuASlqk/53CesBAgjUEkYB9ti0dyFqmicccJkSzHr"}]},"_npmVersion":"1.1.69","_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.14.0":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.14.0","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"\n# gbL.jsMop\n\n## Preamble\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Sending messages\nWhen I think about OO, I think of objects like individual biological cells, which can communicate by emitting messages which can be absorbed by nearby cells.\n\nThis is a bit different than the normal paradigm in most C-like languages - javascript, C#, Java etc.\n\nWhere, in normal javascript, I would write\n\n    listView.render(viewData);\n    \nI would really rather do something like\n\n    send.renderViewList(viewData);\n\nand have this message picked up by the appropriate view. It means I don't have to retain a reference to the receiving object(s), and it fits the biological model more closely.\n\nIn the recipient, I would like to specify messages I will receive. Something like\n\n    receive.renderView(viewData);\n    \nHowever, this kind of paradigm doesn't really exist at a native level in javascript. You can simulate this kind of thing in many ways, including things like the Observer pattern, Bus architectures and Blackboard patterns/architectures.\n\nI wanted something simple, flexible, but also something that worked with a minimum of effort. So I write the gbL.jsMop script as a workaround.\n\n## tl;dr / Show me the money\n\nHere we create a <code>mop</code> object, and create+register a <code>Controller</code> object and two <code>View</code> objects. Then I send a \"show names\" message through the <code>mop</code> which is received by the <code>Controller</code>. The <code>Controller</code> then processes the data into a view model and sends a \"render view list\" message. The \"List\" <code>View</code> object receives this message and renders itself using the view model sent by the <code>Controller</code>.\n\n    var mop = new gbL.jsMop()\n    \t.register(new Controller(), \"List controller\")\n    \t.register(new View(\"List\"), \"List view\")\n    \t.register(new View(\"AnOther\"), \"AnOther view\")\n    \t;\n    \t\n\tvar data = [\n\t\t{ name: \"Jessie\" },\n\t\t{ name: \"Imran\" }\n\t];\n\t\n\t/* \n        When the \"show names\" message is sent, the controller would \n\t    receive it, because it says \"I.receive.showNames\"\n\t*/ \n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n    \n\tfunction View(viewName) {\n\t\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.renderView = function(viewData) {\n\t\t\trenderSelf(viewData);\n\t\t}\n\t\t// ... but only messages ending with my name\n\t\tI.receive.renderView.filter = function(topics, data) {\n\t\t\treturn topics[topics.length] === viewName;\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction renderSelf(viewData) {\n\t\t\t. . .\n\t\t}\n\t}\n \n## Modular design\nI also want to be able to divide my code up into dependency-free units. I don't want my constructor functions for each class of object to reference each other at design time any more than I want my objects to reference each other at run-time….\n\nSo I added the bootstrap pattern. For example:\n\nmain.js\n\n\tvar mop = new gbL.jsMop().boot({\n\t\t\"View factory\" : require(\"./viewFactory\"),\n\t\t\"List controller\" : require(\"./listController\"),\n\t});\n\t\nviewFactory.js\n\n    module.exports.init = function(mop) {\n    \tmop.register(new ViewFactory(mop), \"View factory\");\n    };\n    \n\tfunction ViewFactory(mop) {\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.buildView = function(viewName) {\n\t\t\tvar view = new View(viewName);\n\t\t\tmop.register(view, viewName + \" view\");\n\t\t};\n\t\t\n\t\treturn I;\n\t}\n\n\tfunction View(viewName) {\n\t\t. . .\n\t}\n\nlistController.js\n\n\tmodule.exports.init = function(mop) {\t\n\t\tmop.register(new Controller(), \"List controller\");\n\t}\n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.buildView = function(){};\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tensureListView();\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction ensureListView() {\n\t\t\tI.send.buildView(\"List\");\n\t\t\tensureListView = function() { }; // naughty\n\t\t}\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n\n# Up-to-date example (if below==tl;dr)\n\nThe constructor is divided into two sections:\n\n1. Define the messages received and/or sent\n2. Define business logic in functions\n \nBelow the sections are divided by the line \"return I;\"\n\n    function Controller() {\n    \n\t\t// I will both send and receive messages\n\t\tvar I = { receive: {}, send: {} };\n\t\t\n\t\t// the \"render view\" message - intended for registered Views to receive\n\t\tI.send.renderView = function(viewName, data, res){};\n\t\t\n\t\t// the \"model update request\" message - intended for the model\n\t\tI.send.modelUpdateRequest = function(command){};\n\t\t\n\t\t// the router creates this message on receiving GET /documentList\n\t\tI.receive.GETdocumentList = function(req, res) {\n        \tlistDocuments(function(data) {\n        \t\tI.send.renderView(\"document-list\", data, res);\n        \t});\n        };\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction listDocuments(callback) {\n\t\t\t// send a \"list-documents\" command to the model\n\t\t\tI.send.modelUpdateRequest(\"list-documents\", function(domain) {\n\t\t\t\tcallback(domain.documents);\n\t\t\t});\n\t\t}\n    }\n\nAn object of this type can be registered as normal:\n\n    var mop = new gbL.jsMop();\n    mop.register(new ns.Controller(), \"Documents controller\");\n    mop.register(new ns.ListDocumentsView(), \"List documents view\");\n    mop.reigster(new ns.DomainCommandProcessor(), \"Command interface for the domain\");\n\nor, using the bootstrap pattern (see below):\n\n    new gbL.jsMop().boot({\n        \"controller\" : require(\"./controllers/Controller.js\"),\n        \"documents view\" : require(\"./views/ListDocuments.js\"),\n        \"domain command processor\" : require(\"./model/CommandProcessor.js\")\n    });\n    \nFor this to work, Controller.js would have to include the bootstrapping code which allows modules to initialise themselves and register objects. It would end up looking something like:\n\n    module.exports.bootstrap = function(mop) {\n    \tmop.register(new Controller(), \"Documents controller\");\n    };\n\n\tfunction Controller() {\n\t\t. . . code (as above) goes here . . .\n\t}\n\n\n# tl;dr\n\n### No, really - I mean it. tl;dr\n\n# Version specific notes\nUnless otherwise indicated, the material in the Pervious Versions section still applies\n\n## New in version 0.9.7\n\nTuesday, 20 November 2012\nVersion 0.9.7\n\n### New pattern of registering receive and send messages\nThe principle change in this version is a new facility to receive and send which allows a slightly cleaner syntax. It also encourages you to declare the messages you will send ahead-of-time.\n\n#### \"Interface\" concept\nObjects can now simulate declaration of an interface using the revealing module pattern. Often you will see this:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\t// public members here\n\t\t};\n    \n\t\treturn I;\n\t\t\n\t\t// private functions here\n\t\t\n    }\n    \n#### Receiving and sending\nAn object wishing to receive and/or send should now declare a receive and or send attribute:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\treceive: {\n\t\t\t\t// messages to receive here\n\t\t\t},\n\t\t\tsend: {\n\t\t\t\t//messages to send here\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\t// private functions here\n    }\n\n#### No more underscoring\nMessages in these receive and send attributes should be declared using simple camel casing\n\ne.g.\n\n    this.receive_add_commit_message = function(stuff) {\n    \t// do something with the stuff received\n    };\n\nshould now be written as\n\n\tthis.receive.addCommitMessage = function(stuff) {\n\t\t// do something with the stuff received\n\t};\n\n#### Collect senders at the top\nTo make debugging easier, declare your senders at the top as (usually) empty functions:\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff){};\n    \nafter the object is registered, will send a message with subject \"add commit message\". The inclusion of parameters in the empty function definition is useful as documentation. In addition, you can add your own action which will be called after the message is sent.\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff) {\n    \tlog(\"A commit message has been sent\");\n    };\n    \n## Base Version - 0.9.3\nSunday, 10 June 2012  \nVersion 0.9.3  \n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL-jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = function(initMop) {\n\t\t\tmop = initMop;\n\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL-jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: function(jsMop) {\n\t\t\t\tmop = jsMop;\n\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, toGet)\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","readmeFilename":"README.md","_id":"gbL-jsMop@0.14.0","dist":{"shasum":"a9f7b139faef9db2b612162efe0030d52866f191","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.14.0.tgz","integrity":"sha512-bmowRck66fP1Wx9M9cG6pQZ5YFC+SSzYlNJ//xmgsDrGn0ryGlnY1ZoWacC8bWOr+I+PeLtHW0q3dQQTmc8IaQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFI96h+PH9u7b1F+fhabPHc5tfaLLB+GwDC3OLCnKCGCAiEAor1GP19dLhLNuoO4boEXPKzHFbrDPPH8/aHelErQmVg="}]},"_from":".","_npmVersion":"1.2.4","_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.14.1":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.14.1","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"\n# gbL.jsMop\n\n## Preamble\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Sending messages\nWhen I think about OO, I think of objects like individual biological cells, which can communicate by emitting messages which can be absorbed by nearby cells.\n\nThis is a bit different than the normal paradigm in most C-like languages - javascript, C#, Java etc.\n\nWhere, in normal javascript, I would write\n\n    listView.render(viewData);\n    \nI would really rather do something like\n\n    send.renderViewList(viewData);\n\nand have this message picked up by the appropriate view. It means I don't have to retain a reference to the receiving object(s), and it fits the biological model more closely.\n\nIn the recipient, I would like to specify messages I will receive. Something like\n\n    receive.renderView(viewData);\n    \nHowever, this kind of paradigm doesn't really exist at a native level in javascript. You can simulate this kind of thing in many ways, including things like the Observer pattern, Bus architectures and Blackboard patterns/architectures.\n\nI wanted something simple, flexible, but also something that worked with a minimum of effort. So I write the gbL.jsMop script as a workaround.\n\n## tl;dr / Show me the money\n\nHere we create a <code>mop</code> object, and create+register a <code>Controller</code> object and two <code>View</code> objects. Then I send a \"show names\" message through the <code>mop</code> which is received by the <code>Controller</code>. The <code>Controller</code> then processes the data into a view model and sends a \"render view list\" message. The \"List\" <code>View</code> object receives this message and renders itself using the view model sent by the <code>Controller</code>.\n\n    var mop = new gbL.jsMop()\n    \t.register(new Controller(), \"List controller\")\n    \t.register(new View(\"List\"), \"List view\")\n    \t.register(new View(\"AnOther\"), \"AnOther view\")\n    \t;\n    \t\n\tvar data = [\n\t\t{ name: \"Jessie\" },\n\t\t{ name: \"Imran\" }\n\t];\n\t\n\t/* \n        When the \"show names\" message is sent, the controller would \n\t    receive it, because it says \"I.receive.showNames\"\n\t*/ \n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n    \n\tfunction View(viewName) {\n\t\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.renderView = function(viewData) {\n\t\t\trenderSelf(viewData);\n\t\t}\n\t\t// ... but only messages ending with my name\n\t\tI.receive.renderView.filter = function(topics, data) {\n\t\t\treturn topics[topics.length] === viewName;\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction renderSelf(viewData) {\n\t\t\t. . .\n\t\t}\n\t}\n \n## Modular design\nI also want to be able to divide my code up into dependency-free units. I don't want my constructor functions for each class of object to reference each other at design time any more than I want my objects to reference each other at run-time….\n\nSo I added the bootstrap pattern. For example:\n\nmain.js\n\n\tvar mop = new gbL.jsMop().boot({\n\t\t\"View factory\" : require(\"./viewFactory\"),\n\t\t\"List controller\" : require(\"./listController\"),\n\t});\n\t\nviewFactory.js\n\n    module.exports.init = function(mop) {\n    \tmop.register(new ViewFactory(mop), \"View factory\");\n    };\n    \n\tfunction ViewFactory(mop) {\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.buildView = function(viewName) {\n\t\t\tvar view = new View(viewName);\n\t\t\tmop.register(view, viewName + \" view\");\n\t\t};\n\t\t\n\t\treturn I;\n\t}\n\n\tfunction View(viewName) {\n\t\t. . .\n\t}\n\nlistController.js\n\n\tmodule.exports.init = function(mop) {\t\n\t\tmop.register(new Controller(), \"List controller\");\n\t}\n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.buildView = function(){};\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tensureListView();\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction ensureListView() {\n\t\t\tI.send.buildView(\"List\");\n\t\t\tensureListView = function() { }; // naughty\n\t\t}\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n\n# Up-to-date example (if below==tl;dr)\n\nThe constructor is divided into two sections:\n\n1. Define the messages received and/or sent\n2. Define business logic in functions\n \nBelow the sections are divided by the line \"return I;\"\n\n    function Controller() {\n    \n\t\t// I will both send and receive messages\n\t\tvar I = { receive: {}, send: {} };\n\t\t\n\t\t// the \"render view\" message - intended for registered Views to receive\n\t\tI.send.renderView = function(viewName, data, res){};\n\t\t\n\t\t// the \"model update request\" message - intended for the model\n\t\tI.send.modelUpdateRequest = function(command){};\n\t\t\n\t\t// the router creates this message on receiving GET /documentList\n\t\tI.receive.GETdocumentList = function(req, res) {\n        \tlistDocuments(function(data) {\n        \t\tI.send.renderView(\"document-list\", data, res);\n        \t});\n        };\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction listDocuments(callback) {\n\t\t\t// send a \"list-documents\" command to the model\n\t\t\tI.send.modelUpdateRequest(\"list-documents\", function(domain) {\n\t\t\t\tcallback(domain.documents);\n\t\t\t});\n\t\t}\n    }\n\nAn object of this type can be registered as normal:\n\n    var mop = new gbL.jsMop();\n    mop.register(new ns.Controller(), \"Documents controller\");\n    mop.register(new ns.ListDocumentsView(), \"List documents view\");\n    mop.reigster(new ns.DomainCommandProcessor(), \"Command interface for the domain\");\n\nor, using the bootstrap pattern (see below):\n\n    new gbL.jsMop().boot({\n        \"controller\" : require(\"./controllers/Controller.js\"),\n        \"documents view\" : require(\"./views/ListDocuments.js\"),\n        \"domain command processor\" : require(\"./model/CommandProcessor.js\")\n    });\n    \nFor this to work, Controller.js would have to include the bootstrapping code which allows modules to initialise themselves and register objects. It would end up looking something like:\n\n    module.exports.bootstrap = function(mop) {\n    \tmop.register(new Controller(), \"Documents controller\");\n    };\n\n\tfunction Controller() {\n\t\t. . . code (as above) goes here . . .\n\t}\n\n\n# tl;dr\n\n### No, really - I mean it. tl;dr\n\n# Version specific notes\nUnless otherwise indicated, the material in the Pervious Versions section still applies\n\n## New in version 0.9.7\n\nTuesday, 20 November 2012\nVersion 0.9.7\n\n### New pattern of registering receive and send messages\nThe principle change in this version is a new facility to receive and send which allows a slightly cleaner syntax. It also encourages you to declare the messages you will send ahead-of-time.\n\n#### \"Interface\" concept\nObjects can now simulate declaration of an interface using the revealing module pattern. Often you will see this:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\t// public members here\n\t\t};\n    \n\t\treturn I;\n\t\t\n\t\t// private functions here\n\t\t\n    }\n    \n#### Receiving and sending\nAn object wishing to receive and/or send should now declare a receive and or send attribute:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\treceive: {\n\t\t\t\t// messages to receive here\n\t\t\t},\n\t\t\tsend: {\n\t\t\t\t//messages to send here\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\t// private functions here\n    }\n\n#### No more underscoring\nMessages in these receive and send attributes should be declared using simple camel casing\n\ne.g.\n\n    this.receive_add_commit_message = function(stuff) {\n    \t// do something with the stuff received\n    };\n\nshould now be written as\n\n\tthis.receive.addCommitMessage = function(stuff) {\n\t\t// do something with the stuff received\n\t};\n\n#### Collect senders at the top\nTo make debugging easier, declare your senders at the top as (usually) empty functions:\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff){};\n    \nafter the object is registered, will send a message with subject \"add commit message\". The inclusion of parameters in the empty function definition is useful as documentation. In addition, you can add your own action which will be called after the message is sent.\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff) {\n    \tlog(\"A commit message has been sent\");\n    };\n    \n## Base Version - 0.9.3\nSunday, 10 June 2012  \nVersion 0.9.3  \n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL-jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = function(initMop) {\n\t\t\tmop = initMop;\n\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL-jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: function(jsMop) {\n\t\t\t\tmop = jsMop;\n\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, toGet)\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","readmeFilename":"README.md","_id":"gbL-jsMop@0.14.1","dist":{"shasum":"ac1d724594f7611c3888513c3122ca43ab589108","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.14.1.tgz","integrity":"sha512-Rlb6c5mDnPPzSfUhA65D/ZyOmnKQ0mWAEzlYdv4A21LdqkUMdLwEuVCya9kcdBIxbui1nZ+5D0TAnTSDgK+UTw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCxlKAqIyQofakulRWAwRS1lDoK030eiwT07iGU8DNznQIhAMsDz5YJxr4EfQ+l8igGSk4vJDUKLojQTFS+BMyuzqH3"}]},"_from":".","_npmVersion":"1.2.4","_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.14.2":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.14.2","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"\n# gbL.jsMop\n\n## Preamble\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Sending messages\nWhen I think about OO, I think of objects like individual biological cells, which can communicate by emitting messages which can be absorbed by nearby cells.\n\nThis is a bit different than the normal paradigm in most C-like languages - javascript, C#, Java etc.\n\nWhere, in normal javascript, I would write\n\n    listView.render(viewData);\n    \nI would really rather do something like\n\n    send.renderViewList(viewData);\n\nand have this message picked up by the appropriate view. It means I don't have to retain a reference to the receiving object(s), and it fits the biological model more closely.\n\nIn the recipient, I would like to specify messages I will receive. Something like\n\n    receive.renderView(viewData);\n    \nHowever, this kind of paradigm doesn't really exist at a native level in javascript. You can simulate this kind of thing in many ways, including things like the Observer pattern, Bus architectures and Blackboard patterns/architectures.\n\nI wanted something simple, flexible, but also something that worked with a minimum of effort. So I write the gbL.jsMop script as a workaround.\n\n## tl;dr / Show me the money\n\nHere we create a <code>mop</code> object, and create+register a <code>Controller</code> object and two <code>View</code> objects. Then I send a \"show names\" message through the <code>mop</code> which is received by the <code>Controller</code>. The <code>Controller</code> then processes the data into a view model and sends a \"render view list\" message. The \"List\" <code>View</code> object receives this message and renders itself using the view model sent by the <code>Controller</code>.\n\n    var mop = new gbL.jsMop()\n    \t.register(new Controller(), \"List controller\")\n    \t.register(new View(\"List\"), \"List view\")\n    \t.register(new View(\"AnOther\"), \"AnOther view\")\n    \t;\n    \t\n\tvar data = [\n\t\t{ name: \"Jessie\" },\n\t\t{ name: \"Imran\" }\n\t];\n\t\n\t/* \n        When the \"show names\" message is sent, the controller would \n\t    receive it, because it says \"I.receive.showNames\"\n\t*/ \n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n    \n\tfunction View(viewName) {\n\t\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.renderView = function(viewData) {\n\t\t\trenderSelf(viewData);\n\t\t}\n\t\t// ... but only messages ending with my name\n\t\tI.receive.renderView.filter = function(topics, data) {\n\t\t\treturn topics[topics.length] === viewName;\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction renderSelf(viewData) {\n\t\t\t. . .\n\t\t}\n\t}\n \n## Modular design\nI also want to be able to divide my code up into dependency-free units. I don't want my constructor functions for each class of object to reference each other at design time any more than I want my objects to reference each other at run-time….\n\nSo I added the bootstrap pattern. For example:\n\nmain.js\n\n\tvar mop = new gbL.jsMop().boot({\n\t\t\"View factory\" : require(\"./viewFactory\"),\n\t\t\"List controller\" : require(\"./listController\"),\n\t});\n\t\nviewFactory.js\n\n    module.exports.init = function(mop) {\n    \tmop.register(new ViewFactory(mop), \"View factory\");\n    };\n    \n\tfunction ViewFactory(mop) {\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.buildView = function(viewName) {\n\t\t\tvar view = new View(viewName);\n\t\t\tmop.register(view, viewName + \" view\");\n\t\t};\n\t\t\n\t\treturn I;\n\t}\n\n\tfunction View(viewName) {\n\t\t. . .\n\t}\n\nlistController.js\n\n\tmodule.exports.init = function(mop) {\t\n\t\tmop.register(new Controller(), \"List controller\");\n\t}\n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.buildView = function(){};\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tensureListView();\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction ensureListView() {\n\t\t\tI.send.buildView(\"List\");\n\t\t\tensureListView = function() { }; // naughty\n\t\t}\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n\n# Up-to-date example (if below==tl;dr)\n\nThe constructor is divided into two sections:\n\n1. Define the messages received and/or sent\n2. Define business logic in functions\n \nBelow the sections are divided by the line \"return I;\"\n\n    function Controller() {\n    \n\t\t// I will both send and receive messages\n\t\tvar I = { receive: {}, send: {} };\n\t\t\n\t\t// the \"render view\" message - intended for registered Views to receive\n\t\tI.send.renderView = function(viewName, data, res){};\n\t\t\n\t\t// the \"model update request\" message - intended for the model\n\t\tI.send.modelUpdateRequest = function(command){};\n\t\t\n\t\t// the router creates this message on receiving GET /documentList\n\t\tI.receive.GETdocumentList = function(req, res) {\n        \tlistDocuments(function(data) {\n        \t\tI.send.renderView(\"document-list\", data, res);\n        \t});\n        };\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction listDocuments(callback) {\n\t\t\t// send a \"list-documents\" command to the model\n\t\t\tI.send.modelUpdateRequest(\"list-documents\", function(domain) {\n\t\t\t\tcallback(domain.documents);\n\t\t\t});\n\t\t}\n    }\n\nAn object of this type can be registered as normal:\n\n    var mop = new gbL.jsMop();\n    mop.register(new ns.Controller(), \"Documents controller\");\n    mop.register(new ns.ListDocumentsView(), \"List documents view\");\n    mop.reigster(new ns.DomainCommandProcessor(), \"Command interface for the domain\");\n\nor, using the bootstrap pattern (see below):\n\n    new gbL.jsMop().boot({\n        \"controller\" : require(\"./controllers/Controller.js\"),\n        \"documents view\" : require(\"./views/ListDocuments.js\"),\n        \"domain command processor\" : require(\"./model/CommandProcessor.js\")\n    });\n    \nFor this to work, Controller.js would have to include the bootstrapping code which allows modules to initialise themselves and register objects. It would end up looking something like:\n\n    module.exports.bootstrap = function(mop) {\n    \tmop.register(new Controller(), \"Documents controller\");\n    };\n\n\tfunction Controller() {\n\t\t. . . code (as above) goes here . . .\n\t}\n\n\n# tl;dr\n\n### No, really - I mean it. tl;dr\n\n# Version specific notes\nUnless otherwise indicated, the material in the Pervious Versions section still applies\n\n## New in version 0.9.7\n\nTuesday, 20 November 2012\nVersion 0.9.7\n\n### New pattern of registering receive and send messages\nThe principle change in this version is a new facility to receive and send which allows a slightly cleaner syntax. It also encourages you to declare the messages you will send ahead-of-time.\n\n#### \"Interface\" concept\nObjects can now simulate declaration of an interface using the revealing module pattern. Often you will see this:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\t// public members here\n\t\t};\n    \n\t\treturn I;\n\t\t\n\t\t// private functions here\n\t\t\n    }\n    \n#### Receiving and sending\nAn object wishing to receive and/or send should now declare a receive and or send attribute:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\treceive: {\n\t\t\t\t// messages to receive here\n\t\t\t},\n\t\t\tsend: {\n\t\t\t\t//messages to send here\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\t// private functions here\n    }\n\n#### No more underscoring\nMessages in these receive and send attributes should be declared using simple camel casing\n\ne.g.\n\n    this.receive_add_commit_message = function(stuff) {\n    \t// do something with the stuff received\n    };\n\nshould now be written as\n\n\tthis.receive.addCommitMessage = function(stuff) {\n\t\t// do something with the stuff received\n\t};\n\n#### Collect senders at the top\nTo make debugging easier, declare your senders at the top as (usually) empty functions:\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff){};\n    \nafter the object is registered, will send a message with subject \"add commit message\". The inclusion of parameters in the empty function definition is useful as documentation. In addition, you can add your own action which will be called after the message is sent.\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff) {\n    \tlog(\"A commit message has been sent\");\n    };\n    \n## Base Version - 0.9.3\nSunday, 10 June 2012  \nVersion 0.9.3  \n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL-jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = function(initMop) {\n\t\t\tmop = initMop;\n\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL-jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: function(jsMop) {\n\t\t\t\tmop = jsMop;\n\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, toGet)\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","readmeFilename":"README.md","_id":"gbL-jsMop@0.14.2","dist":{"shasum":"83e391c99597d383f66a8b48dc598f0934c80cfb","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.14.2.tgz","integrity":"sha512-psUVlAofvOkymmJtuezBBTiM+RYjwBhzQhHasdIguYzsFNCWjBmNuI/td0Bh50jOkGUPoSNvZxctPvdYHTpeDg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF42QMr+HbYJop/DHufpWUgeRfHrtXPVh+Ose3w37IZgAiAEInriZJjN7K1uTvi5kwTqgiMyGBMWMjQacZGVzISD0Q=="}]},"_from":".","_npmVersion":"1.2.4","_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.14.3":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.14.3","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"\n# gbL.jsMop\n\n## Preamble\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Sending messages\nWhen I think about OO, I think of objects like individual biological cells, which can communicate by emitting messages which can be absorbed by nearby cells.\n\nThis is a bit different than the normal paradigm in most C-like languages - javascript, C#, Java etc.\n\nWhere, in normal javascript, I would write\n\n    listView.render(viewData);\n    \nI would really rather do something like\n\n    send.renderViewList(viewData);\n\nand have this message picked up by the appropriate view. It means I don't have to retain a reference to the receiving object(s), and it fits the biological model more closely.\n\nIn the recipient, I would like to specify messages I will receive. Something like\n\n    receive.renderView(viewData);\n    \nHowever, this kind of paradigm doesn't really exist at a native level in javascript. You can simulate this kind of thing in many ways, including things like the Observer pattern, Bus architectures and Blackboard patterns/architectures.\n\nI wanted something simple, flexible, but also something that worked with a minimum of effort. So I write the gbL.jsMop script as a workaround.\n\n## tl;dr / Show me the money\n\nHere we create a <code>mop</code> object, and create+register a <code>Controller</code> object and two <code>View</code> objects. Then I send a \"show names\" message through the <code>mop</code> which is received by the <code>Controller</code>. The <code>Controller</code> then processes the data into a view model and sends a \"render view list\" message. The \"List\" <code>View</code> object receives this message and renders itself using the view model sent by the <code>Controller</code>.\n\n    var mop = new gbL.jsMop()\n    \t.register(new Controller(), \"List controller\")\n    \t.register(new View(\"List\"), \"List view\")\n    \t.register(new View(\"AnOther\"), \"AnOther view\")\n    \t;\n    \t\n\tvar data = [\n\t\t{ name: \"Jessie\" },\n\t\t{ name: \"Imran\" }\n\t];\n\t\n\t/* \n        When the \"show names\" message is sent, the controller would \n\t    receive it, because it says \"I.receive.showNames\"\n\t*/ \n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n    \n\tfunction View(viewName) {\n\t\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.renderView = function(viewData) {\n\t\t\trenderSelf(viewData);\n\t\t}\n\t\t// ... but only messages ending with my name\n\t\tI.receive.renderView.filter = function(topics, data) {\n\t\t\treturn topics[topics.length] === viewName;\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction renderSelf(viewData) {\n\t\t\t. . .\n\t\t}\n\t}\n \n## Modular design\nI also want to be able to divide my code up into dependency-free units. I don't want my constructor functions for each class of object to reference each other at design time any more than I want my objects to reference each other at run-time….\n\nSo I added the bootstrap pattern. For example:\n\nmain.js\n\n\tvar mop = new gbL.jsMop().boot({\n\t\t\"View factory\" : require(\"./viewFactory\"),\n\t\t\"List controller\" : require(\"./listController\"),\n\t});\n\t\nviewFactory.js\n\n    module.exports.init = function(mop) {\n    \tmop.register(new ViewFactory(mop), \"View factory\");\n    };\n    \n\tfunction ViewFactory(mop) {\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.buildView = function(viewName) {\n\t\t\tvar view = new View(viewName);\n\t\t\tmop.register(view, viewName + \" view\");\n\t\t};\n\t\t\n\t\treturn I;\n\t}\n\n\tfunction View(viewName) {\n\t\t. . .\n\t}\n\nlistController.js\n\n\tmodule.exports.init = function(mop) {\t\n\t\tmop.register(new Controller(), \"List controller\");\n\t}\n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.buildView = function(){};\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tensureListView();\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction ensureListView() {\n\t\t\tI.send.buildView(\"List\");\n\t\t\tensureListView = function() { }; // naughty\n\t\t}\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n\n# Up-to-date example (if below==tl;dr)\n\nThe constructor is divided into two sections:\n\n1. Define the messages received and/or sent\n2. Define business logic in functions\n \nBelow the sections are divided by the line \"return I;\"\n\n    function Controller() {\n    \n\t\t// I will both send and receive messages\n\t\tvar I = { receive: {}, send: {} };\n\t\t\n\t\t// the \"render view\" message - intended for registered Views to receive\n\t\tI.send.renderView = function(viewName, data, res){};\n\t\t\n\t\t// the \"model update request\" message - intended for the model\n\t\tI.send.modelUpdateRequest = function(command){};\n\t\t\n\t\t// the router creates this message on receiving GET /documentList\n\t\tI.receive.GETdocumentList = function(req, res) {\n        \tlistDocuments(function(data) {\n        \t\tI.send.renderView(\"document-list\", data, res);\n        \t});\n        };\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction listDocuments(callback) {\n\t\t\t// send a \"list-documents\" command to the model\n\t\t\tI.send.modelUpdateRequest(\"list-documents\", function(domain) {\n\t\t\t\tcallback(domain.documents);\n\t\t\t});\n\t\t}\n    }\n\nAn object of this type can be registered as normal:\n\n    var mop = new gbL.jsMop();\n    mop.register(new ns.Controller(), \"Documents controller\");\n    mop.register(new ns.ListDocumentsView(), \"List documents view\");\n    mop.reigster(new ns.DomainCommandProcessor(), \"Command interface for the domain\");\n\nor, using the bootstrap pattern (see below):\n\n    new gbL.jsMop().boot({\n        \"controller\" : require(\"./controllers/Controller.js\"),\n        \"documents view\" : require(\"./views/ListDocuments.js\"),\n        \"domain command processor\" : require(\"./model/CommandProcessor.js\")\n    });\n    \nFor this to work, Controller.js would have to include the bootstrapping code which allows modules to initialise themselves and register objects. It would end up looking something like:\n\n    module.exports.bootstrap = function(mop) {\n    \tmop.register(new Controller(), \"Documents controller\");\n    };\n\n\tfunction Controller() {\n\t\t. . . code (as above) goes here . . .\n\t}\n\n\n# tl;dr\n\n### No, really - I mean it. tl;dr\n\n# Version specific notes\nUnless otherwise indicated, the material in the Pervious Versions section still applies\n\n## New in version 0.9.7\n\nTuesday, 20 November 2012\nVersion 0.9.7\n\n### New pattern of registering receive and send messages\nThe principle change in this version is a new facility to receive and send which allows a slightly cleaner syntax. It also encourages you to declare the messages you will send ahead-of-time.\n\n#### \"Interface\" concept\nObjects can now simulate declaration of an interface using the revealing module pattern. Often you will see this:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\t// public members here\n\t\t};\n    \n\t\treturn I;\n\t\t\n\t\t// private functions here\n\t\t\n    }\n    \n#### Receiving and sending\nAn object wishing to receive and/or send should now declare a receive and or send attribute:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\treceive: {\n\t\t\t\t// messages to receive here\n\t\t\t},\n\t\t\tsend: {\n\t\t\t\t//messages to send here\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\t// private functions here\n    }\n\n#### No more underscoring\nMessages in these receive and send attributes should be declared using simple camel casing\n\ne.g.\n\n    this.receive_add_commit_message = function(stuff) {\n    \t// do something with the stuff received\n    };\n\nshould now be written as\n\n\tthis.receive.addCommitMessage = function(stuff) {\n\t\t// do something with the stuff received\n\t};\n\n#### Collect senders at the top\nTo make debugging easier, declare your senders at the top as (usually) empty functions:\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff){};\n    \nafter the object is registered, will send a message with subject \"add commit message\". The inclusion of parameters in the empty function definition is useful as documentation. In addition, you can add your own action which will be called after the message is sent.\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff) {\n    \tlog(\"A commit message has been sent\");\n    };\n    \n## Base Version - 0.9.3\nSunday, 10 June 2012  \nVersion 0.9.3  \n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL-jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = function(initMop) {\n\t\t\tmop = initMop;\n\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL-jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: function(jsMop) {\n\t\t\t\tmop = jsMop;\n\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, toGet)\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","readmeFilename":"README.md","_id":"gbL-jsMop@0.14.3","dist":{"shasum":"13ea81d2269445b25b085559d8ff959d7dca9fc5","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.14.3.tgz","integrity":"sha512-wdAdwIwJML6KQSxVdlh94nZ+8vusoNLqEl38ycUTVIZU17z/5NXGK05TRv9stLCF6YKhpiUzmenX9wvhES2NDw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCMpHB7M1CswI5br5CkUZKDHld+X/rP6cBiDZAjE/vXBQIhAMHwj7rGJIY33JlH0HWLyuk96gCxtWX+sVM8KvcG6yO4"}]},"_from":".","_npmVersion":"1.2.4","_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]},"0.14.4":{"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"name":"gbL-jsMop","description":"Message passing library","version":"0.14.4","homepage":"http://goofballLogic.github.com/gbL.jsMop","repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"},"main":"gbL.jsMop.js","scripts":{"test":"make test"},"dependencies":{},"devDependencies":{},"optionalDependencies":{},"engines":{"node":"*"},"readme":"\n# gbL.jsMop\n\n## Preamble\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Sending messages\nWhen I think about OO, I think of objects like individual biological cells, which can communicate by emitting messages which can be absorbed by nearby cells.\n\nThis is a bit different than the normal paradigm in most C-like languages - javascript, C#, Java etc.\n\nWhere, in normal javascript, I would write\n\n    listView.render(viewData);\n    \nI would really rather do something like\n\n    send.renderViewList(viewData);\n\nand have this message picked up by the appropriate view. It means I don't have to retain a reference to the receiving object(s), and it fits the biological model more closely.\n\nIn the recipient, I would like to specify messages I will receive. Something like\n\n    receive.renderView(viewData);\n    \nHowever, this kind of paradigm doesn't really exist at a native level in javascript. You can simulate this kind of thing in many ways, including things like the Observer pattern, Bus architectures and Blackboard patterns/architectures.\n\nI wanted something simple, flexible, but also something that worked with a minimum of effort. So I write the gbL.jsMop script as a workaround.\n\n## tl;dr / Show me the money\n\nHere we create a <code>mop</code> object, and create+register a <code>Controller</code> object and two <code>View</code> objects. Then I send a \"show names\" message through the <code>mop</code> which is received by the <code>Controller</code>. The <code>Controller</code> then processes the data into a view model and sends a \"render view list\" message. The \"List\" <code>View</code> object receives this message and renders itself using the view model sent by the <code>Controller</code>.\n\n    var mop = new gbL.jsMop()\n    \t.register(new Controller(), \"List controller\")\n    \t.register(new View(\"List\"), \"List view\")\n    \t.register(new View(\"AnOther\"), \"AnOther view\")\n    \t;\n    \t\n\tvar data = [\n\t\t{ name: \"Jessie\" },\n\t\t{ name: \"Imran\" }\n\t];\n\t\n\t/* \n        When the \"show names\" message is sent, the controller would \n\t    receive it, because it says \"I.receive.showNames\"\n\t*/ \n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n    \n\tfunction View(viewName) {\n\t\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.renderView = function(viewData) {\n\t\t\trenderSelf(viewData);\n\t\t}\n\t\t// ... but only messages ending with my name\n\t\tI.receive.renderView.filter = function(topics, data) {\n\t\t\treturn topics[topics.length] === viewName;\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction renderSelf(viewData) {\n\t\t\t. . .\n\t\t}\n\t}\n \n## Modular design\nI also want to be able to divide my code up into dependency-free units. I don't want my constructor functions for each class of object to reference each other at design time any more than I want my objects to reference each other at run-time….\n\nSo I added the bootstrap pattern. For example:\n\nmain.js\n\n\tvar mop = new gbL.jsMop().boot({\n\t\t\"View factory\" : require(\"./viewFactory\"),\n\t\t\"List controller\" : require(\"./listController\"),\n\t});\n\t\nviewFactory.js\n\n    module.exports.init = function(mop) {\n    \tmop.register(new ViewFactory(mop), \"View factory\");\n    };\n    \n\tfunction ViewFactory(mop) {\n\t\tvar I = { receive: {} };\n\t\t\n\t\t// messages I receive\n\t\tI.receive.buildView = function(viewName) {\n\t\t\tvar view = new View(viewName);\n\t\t\tmop.register(view, viewName + \" view\");\n\t\t};\n\t\t\n\t\treturn I;\n\t}\n\n\tfunction View(viewName) {\n\t\t. . .\n\t}\n\nlistController.js\n\n\tmodule.exports.init = function(mop) {\t\n\t\tmop.register(new Controller(), \"List controller\");\n\t}\n\t\n    function Controller() {\n    \n    \tvar I = { send: function() {}, receive: {} };\n\t\t\n\t\t// messages I send\n\t\tI.send.buildView = function(){};\n\t\tI.send.renderViewList = function(viewData){};\n\t\t\n\t\t// messages I receive\n\t\tI.receive.showNames = function(items) {\n\t\t\tensureListView();\n\t\t\tvar viewData = generateNameListViewModel(items);\n\t\t\tI.send.renderViewList(viewData);\n\t\t};\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction ensureListView() {\n\t\t\tI.send.buildView(\"List\");\n\t\t\tensureListView = function() { }; // naughty\n\t\t}\n\t\t\n\t\tfunction generateNameListViewModel(items) {\n\t\t\t. . .\n\t\t}\n    }\n\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n\n# Up-to-date example (if below==tl;dr)\n\nThe constructor is divided into two sections:\n\n1. Define the messages received and/or sent\n2. Define business logic in functions\n \nBelow the sections are divided by the line \"return I;\"\n\n    function Controller() {\n    \n\t\t// I will both send and receive messages\n\t\tvar I = { receive: {}, send: {} };\n\t\t\n\t\t// the \"render view\" message - intended for registered Views to receive\n\t\tI.send.renderView = function(viewName, data, res){};\n\t\t\n\t\t// the \"model update request\" message - intended for the model\n\t\tI.send.modelUpdateRequest = function(command){};\n\t\t\n\t\t// the router creates this message on receiving GET /documentList\n\t\tI.receive.GETdocumentList = function(req, res) {\n        \tlistDocuments(function(data) {\n        \t\tI.send.renderView(\"document-list\", data, res);\n        \t});\n        };\n\t\t\n\t\treturn I;\n\t\t\n\t\tfunction listDocuments(callback) {\n\t\t\t// send a \"list-documents\" command to the model\n\t\t\tI.send.modelUpdateRequest(\"list-documents\", function(domain) {\n\t\t\t\tcallback(domain.documents);\n\t\t\t});\n\t\t}\n    }\n\nAn object of this type can be registered as normal:\n\n    var mop = new gbL.jsMop();\n    mop.register(new ns.Controller(), \"Documents controller\");\n    mop.register(new ns.ListDocumentsView(), \"List documents view\");\n    mop.reigster(new ns.DomainCommandProcessor(), \"Command interface for the domain\");\n\nor, using the bootstrap pattern (see below):\n\n    new gbL.jsMop().boot({\n        \"controller\" : require(\"./controllers/Controller.js\"),\n        \"documents view\" : require(\"./views/ListDocuments.js\"),\n        \"domain command processor\" : require(\"./model/CommandProcessor.js\")\n    });\n    \nFor this to work, Controller.js would have to include the bootstrapping code which allows modules to initialise themselves and register objects. It would end up looking something like:\n\n    module.exports.bootstrap = function(mop) {\n    \tmop.register(new Controller(), \"Documents controller\");\n    };\n\n\tfunction Controller() {\n\t\t. . . code (as above) goes here . . .\n\t}\n\n\n# tl;dr\n\n### No, really - I mean it. tl;dr\n\n# Version specific notes\nUnless otherwise indicated, the material in the Pervious Versions section still applies\n\n## New in version 0.9.7\n\nTuesday, 20 November 2012\nVersion 0.9.7\n\n### New pattern of registering receive and send messages\nThe principle change in this version is a new facility to receive and send which allows a slightly cleaner syntax. It also encourages you to declare the messages you will send ahead-of-time.\n\n#### \"Interface\" concept\nObjects can now simulate declaration of an interface using the revealing module pattern. Often you will see this:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\t// public members here\n\t\t};\n    \n\t\treturn I;\n\t\t\n\t\t// private functions here\n\t\t\n    }\n    \n#### Receiving and sending\nAn object wishing to receive and/or send should now declare a receive and or send attribute:\n\n    function Controller() {\n    \n\t\tvar I = {\n\t\t\treceive: {\n\t\t\t\t// messages to receive here\n\t\t\t},\n\t\t\tsend: {\n\t\t\t\t//messages to send here\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn I;\n\t\t\n\t\t// private functions here\n    }\n\n#### No more underscoring\nMessages in these receive and send attributes should be declared using simple camel casing\n\ne.g.\n\n    this.receive_add_commit_message = function(stuff) {\n    \t// do something with the stuff received\n    };\n\nshould now be written as\n\n\tthis.receive.addCommitMessage = function(stuff) {\n\t\t// do something with the stuff received\n\t};\n\n#### Collect senders at the top\nTo make debugging easier, declare your senders at the top as (usually) empty functions:\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff){};\n    \nafter the object is registered, will send a message with subject \"add commit message\". The inclusion of parameters in the empty function definition is useful as documentation. In addition, you can add your own action which will be called after the message is sent.\n\ne.g.\n\n    this.send.addCommitMessage = function(stuff) {\n    \tlog(\"A commit message has been sent\");\n    };\n    \n## Base Version - 0.9.3\nSunday, 10 June 2012  \nVersion 0.9.3  \n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL-jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = function(initMop) {\n\t\t\tmop = initMop;\n\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL-jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: function(jsMop) {\n\t\t\t\tmop = jsMop;\n\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, toGet)\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","readmeFilename":"README.md","_id":"gbL-jsMop@0.14.4","dist":{"shasum":"f118a79452b27cc35875b87c6f62bb60562a5876","tarball":"https://registry.npmjs.org/gbL-jsMop/-/gbL-jsMop-0.14.4.tgz","integrity":"sha512-8cvze5S+JeyNwH8gEVzjfja7gI6EIg/HVbXmMcbMqX7a0v2iwNTH5OG7bKIbeV2xl8ilYhd1y1Nw3XVGK3SRXw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDIdRZvrSv66lbcOtA/Sng3bZqiJcOQBTFhhb1YmTWIfQIhAJx0Q/ODzM73TU7DMT//fHGrNXoVCE01kfg1ddYxjBmW"}]},"_from":".","_npmVersion":"1.2.4","_npmUser":{"name":"goofballLogic","email":"andrew@goofballLogic.com"},"maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}]}},"readme":"\n\n# gbL.jsMop\n\nSunday, 10 June 2010  \nVersion 0.9.3  \nN.B. Much of the code below has not been tested. For tested examples, see the tests and scenarios included. Feel free to contact me with abuse or questions: disqus at\nhttp://goofballLogic.github.com/gbL.jsMop\n\n## Preamble\nThis is a library for message passing in javascript. The \"mop\" in jsMop is an acronym referring to OOP, but \"message-oriented\" instead of \"object-oriented\". A central \"mop\" object is used to send and receive messages (in place of a native message exchange construct).\n\nhttp://www.purl.org/stefan_ram/pub/doc_kay_oop_en\n\n## Environment\nDesigned to work specifically in the browser, or in Node, but should work in most CommonJS environments.\n\n## Running/Building tests\n####Without a browser (mocha)\nYou will need to\n\n    npm install mocha\n    npm install expect.js\n\nand then\n\n    make test\n\n####In the browser\nJust browse to \n\n    test-browser/browserTests.html\n\n####Building (and opening) the browser tests\nYou will need to\n\n    npm install browserify\n\nand then\n\n    make browser-test\n\n## Examples\nExample usage can be found in the /test/scenarios folder.\n\n### Basic usage\n\n####First step is to spin up a hub for the messages:\n\n    var mop = new gbL.jsMop.Mop();\n\nor\n\n    var mop = new require(\"gbL.jsMop\").Mop();\n\n####Sending\n\nThen, to send a message:\n\n    mop.send(\"Hello world\").as(\"test\");\n\nwhich sends a message with subject __*test*__ and payload of __*Hello world*__.\n\n####Receiving\nIf I am an object wanting to receive this sort of message, I would include a method named __receive_test__:\n\n    var receiver = {\n        receive_test: function(data) {\n            console.log(data);\n        }\n    };\n\nand I would register with the hub to receive messages:\n\n    mop.register(receiver, \"My first receiver\");\n\n#####_or_\n\nif I don't wish to register as an object, I can regsiter a call back function:\n\n    mop.registerHandler(\"test\", function(data) {\n        console.log(data);\n    });\n\n##Debugging\nThere are a few tools to help with debugging message passing. For analysis of registered objects and handlers, just send a census message:\n\n\tvar registered = mop.send().as(\"census\");\n\tconsole.log(\"Registered receivers: \" + registered.join(\", \");\n\t\nYou may also wish to turn on console logging by using:\n\n\tmop.debug = true;\n\t\nor\n\n\tmop.send.debug = true;\n\n##Bootstrapping modules\nSay you have a set of modules which contain objects wishing to participate in message exchange through a given mop. \n\nFor example, in Node, you might have a console-logger.js:\n\n\t(function(context) {\n\t\t\n\t\tvar mop;\n\t\t\n\t\tcontext.bootstrap = {\n\t\t\tinit: function(initMop) {\n\t\t\t\tmop = initMop;\n\t\t\t\tinitMop.Register(loggingSingleton, \"Console logger\");\n\t\t\t}\n\t\t}\n\t\t\n\t\tvar loggingSingleton = new function() {\n\t\t\treturn {\n\t\t\t\treceive_log: function(data) {\n\t\t\t\t\tvar label = mop.topics.slice(1).join(\" \");\n\t\t\t\t\tconsole.log(label, data);\n\t\t\t\t}\n\t\t\t};\n\t\t}();\n\t\t\n\t})(module.exports);\n\t\nand then as part of bootstrapping, include the console-logger:\n\n\tvar mop = new require(\"gbL.jsMop\").Mop();\n\tmop.boot({\n\t\t\"logger\": require(\"console-logger\"),\n\t\t\"worker\": require(\"important-worker-module\"),\n\t\t\"another\": require(\"another-important-worker-module\")\n\t});\n\nwhich will mean that e.g. the following will print my friend's name to the console:\n\n\tmop.send(\"Lisa Jue Bishop\").as(\"log the name of my dear friend\");\n\t\n#####Or\nIn the browser, you might have a ticker object:\n\n\t(function(context) {\n\t\tvar mop;\n\t\t\n\t\tcontext.Ticker = {\n\t\t\tbootstrap: {\n\t\t\t\tinit: function(jsMop) {\n\t\t\t\t\tmop = jsMop;\n\t\t\t\t\tmop.register(new Ticker(), \"Ticker\");\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\t\n\t\tfunction Ticker() {\n\t\t\t// private state and behaviours\n\t\t\tvar cancelled = false;\n\t\t\tfunction tick() {\n\t\t\t\tmop.send().as(\"tick\");\n\t\t\t\tif(!cancelled) setTimeout(100, tick);\n\t\t\t}\n\t\t\t// message receivers\n\t\t\treturn {\n\t\t\t\treceive_cancel_ticker: function() {\n\t\t\t\t\tcancelled = true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t})(gbL.Stocks || { gbL.Stocks = {} });\n\nwhich you could then boot as so:\n\n\tvar mop = new gbL.jsMop.Mop();\n\tmop.boot({\n\t\t\"ticker\": gbL.Stocks.Ticker,\n\t\t\"symbol-list\": gbL.Stocks.SymbolLister\n\t});\n\t\nwhich will cause <code>tick</code> messages to be sent until:\n\n\tmop.send().as(\"cancel ticker\");\n\t\nis sent.\n\t\n##Further patterns\n\n####Partial subject match\nIf you want to accept messages about a more general subject than those specified for the messages, you can receive messages which match the start of the subject:\n\n    function HelloListener() {\n    \tthis.receive_hello = function() {\n    \t\tconsole.log(mop.subject);\n    \t};\n    }\n\nwould receive:\n\n\tmop.send().as(\"hello world\");\n\t\nbut would also receive:\n\n\tmop.send().as(\"hello heaven\");\n\tmop.send().as(\"hello hell\");\n\n####Filtering messages\nIf you want to filter the messages received for a given subject, you can attaching a filtering function, like so:\n\n    function BeerWatcher() {\n    \tthis.receive_important_notification = function(notification) {\n    \t\tconsole.log(\"CRITICAL: \" + notification);\n    \t};\n    \tthis.receive_important_notification.filter = function(topics, data)\n    \t{\n    \t\t// only interested in notifications mentioning beer in their subject\n    \t\treturn ~topics.join(\" \").indexOf(\"beer\");\n    \t};\n    }\n\n####Filtering lots of handlers\nIf you have an object which only wants to receive messages which mention a specific ID, you can:\n\n\tfunction CalculationNode(nodeId, calculationStrategy) {\n\t\t// private state and behaviour\n\t\tvar parameters, lastResult;\n\t\tfunction reset(preserveResult) { \n\t\t\tparameters = [];\n\t\t\tpreserveResult || lastResult = null; \n\t\t}\n\t\tfunction execute() {\n\t\t\treturn (lastResult = calculationStrategy.apply(this, parameters));\n\t\t}\n\t\treset();\n\t\t\n\t\t// message receivers\n\t\tthis.receive_reset_parameters = function() {\n\t\t\treset(true);\n\t\t};\n\t\tthis.receive_parameterise = function() {\n\t\t\tfor(var i in arguments) parameters.push(arguments[i]);\n\t\t};\n\t\tthis.receive_calculate = function() {\n\t\t\tmop.send(execute()).as(\"result for node \" + nodeId);\n\t\t};\n\n\t\tmop.setReceiveFilters(this, function(topics, data) {\n\t\t\t// all the above, only for messages about this node (by Id)\n\t\t\treturn ~topics.indexOf(\"node \" + nodeId);\n\t\t});\n\t\t\n\t\t// unfiltered receivers\n\t\tthis.receive_global_reset = function() {\n\t\t\treset();\n\t\t};\n\t\tthis.receive_return_results = function() {\n\t\t\treturn new function() { this[nodeId] = lastResult; };\n\t\t}\n\t}\n\n####Adapter\nYou may wish to use an adapter to send and receive messages, especially when you want to mix the message-passing paradigm with calling methods directly. For example, using the revealing module pattern, you might do something like:\n\n    function ServiceAgent() {\n\n        var configuration = null;\n\t\tvar fetched = [];\n\t\t\n        function saveConfiguration(config) {\n            configuration = $(config).clone();\n        }\n        \n\t\tfunction dataGet(toGet) {\n\t\t\treturn mop\n\t\t\t\t.send(configuration.baseUrl, \"orders\")\n\t\t\t\t.as(\"ajax GET\");\n\t\t}\n\t\t\n\t\tfunction injestData(data) {\n\t\t\tfetched.push(data);\n\t\t}\n\t\t\n        // inner facet (mop adapter)\n        mop.register({\n        \treceive_configuration: saveConfiguration,\n        \treceive_data_received: injestData,\n        }, \"Service Agent\");\n        \n\t\t// outer facet (revealed methods)\n        return {\n            listOrders: function() {\n            \tvar data = null;\n            \tif(dataGet(\"orders\")) data = fetched.pop();\n            \treturn data;\n           \t}\n        };\n    }\n\nAn object constructed by this function will expect to collaborate with\n - An object whose responsibility is to broadcast configuration (sending messages with subject \"configuration\")\n - An object whose responsibility is to make AJAX calls (receiving subjects beginning with \"ajax\", and sending back the data with subject \"data received\")\n\nAnd it exposes a method which can be called directly as so:\n\n    var serviceAgent = new ServiceAgent();\n    var orders = serviceAgent.listOrders();\n    \n\n","maintainers":[{"name":"goofballLogic","email":"andrew@goofballLogic.com"}],"time":{"modified":"2022-06-18T05:04:23.861Z","created":"2012-06-10T15:06:05.408Z","0.9.3":"2012-06-10T15:06:06.879Z","0.9.5":"2012-07-07T23:11:05.441Z","0.9.6":"2012-07-07T23:15:34.643Z","0.9.7":"2012-07-12T16:55:37.155Z","0.10.0":"2012-09-29T17:33:11.920Z","0.11.0":"2012-09-29T18:30:24.108Z","0.12.0":"2012-11-20T18:18:39.298Z","0.13.0":"2013-01-11T16:08:33.350Z","0.13.1":"2013-01-11T16:39:17.606Z","0.13.2":"2013-01-11T16:41:40.998Z","0.14.0":"2013-01-30T21:35:48.780Z","0.14.1":"2013-03-23T17:17:15.811Z","0.14.2":"2013-03-26T17:21:47.216Z","0.14.3":"2013-04-05T21:23:07.198Z","0.14.4":"2013-04-11T19:30:36.871Z"},"author":{"name":"Andrew Stewart Gibson","email":"andrew@goofballLogic.com"},"repository":{"type":"git","url":"git://github.com/goofballLogic/gbL.jsMop.git"}}