Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

famous-mediator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

famous-mediator - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

16

index.js

@@ -24,3 +24,3 @@ define(function(require, exports, module) {

Mediator.xxxx
Engine.on('created:xxxx',function(xxxx){ .... });
Mediator.on('created:xxxx',function(xxxx){ .... });
```

@@ -38,5 +38,4 @@

var Mediator = require('famous-mediator');
var Engine = require('famous/core/Engine');
Engine.on('created:Router',function(router){
Mediator.on('created:Router',function(router){
router.on('change',function(name){

@@ -52,6 +51,7 @@ Mediator.pages.set(name);

// cache for all modules that are created
var modules = window.Modules = {};
var Mediator = window.Mediator = {};
Mediator.on = Engine.on;
// when a module is created...
Engine.on('created',function(module){
Mediator.on('created',function(module){

@@ -68,3 +68,3 @@ // try to find a name

if(name) {
modules[name] = module; // store module for later reference
Mediator[name] = module; // store module for later reference
Engine.emit('created:'+name,module); // broadcast module creation

@@ -74,3 +74,3 @@ }

module.exports = modules;
module.exports = Mediator;
});
{
"name": "famous-mediator",
"version": "0.1.0",
"version": "0.1.1",
"description": "Utilities for a mediator design pattern in Famo.us",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -14,10 +14,50 @@ famous-mediator

```
## Example
## Usage
Imagine you have a `Router` module and a `pages` module:
The Famo.us Engine is used as a global eventbus to announce creation of modules.
*1. Router.js - does it's thing and doesn't know about other modules*
```javascript
function Router(){
// blablabla
this.name = 'router';
Engine.emit('created',this) // broadcast created event
// blablabla
}
```
If you want to register a module, simple call in your constructor function:
*2. PageController.js - displays pages but doesn't know about any routes!*
```javascript
function PageController(){
// blablabla
this.name = 'pages'; // name your module
Engine.emit('created',this) // broadcast created event
// blablabla
}
```
*3. RouteMediator.js - couples the router and pages together!*
```javascript
var Mediator = require('famous-mediator');;
Mediator.on('created:Router',function(router){
router.on('change',function(name){
Mediator.pages.setPage(name);
});
});
```
## Benefits
Using the mediator pattern to decouple modules
* Promotes clean, reusable modules
* Clear seperation of concerns - no more sneaky business logic in your templates!
* Is the perfect place for hacks, experiments, monkey-patches and workarounds. And because all of your "bad" code is in the Mediators, your actual code base stays clean! (True story!)
## Usage
The Famo.us Engine is used as a global eventbus to announce creation of modules. If you want to register a module, simple call in your constructor function:
```javascript
Engine.emit('created',this)

@@ -38,3 +78,3 @@ ````

Mediator.xxxx
Engine.on('created:xxxx',function(xxxx){ .... });
Mediator.on('created:xxxx',function(xxxx){ .... });
```

@@ -48,14 +88,7 @@

For example, imagine you have a `Router` module and a `pages` module:
## Changelog
```
var Mediator = require('famous-mediator');
var Engine = require('famous/core/Engine');
### 0.1.1 (31/10/2014)
Engine.on('created:Router',function(router){
router.on('change',function(name){
Mediator.pages.set(name);
});
});
```
* Aliased `Mediator.on` to `Engine.on`.

@@ -62,0 +95,0 @@ ## Contribute

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc