Skip to content

Instantly share code, notes, and snippets.

Created November 19, 2015 19:08
Show Gist options
  • Save anonymous/22855b97157e96923af9 to your computer and use it in GitHub Desktop.
Save anonymous/22855b97157e96923af9 to your computer and use it in GitHub Desktop.
Relux Join // source http://jsbin.com/tahufucohu
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Relux Join</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.12.2/react.js"></script>
<script src="https://rawgit.com/spoike/refluxjs/master/dist/reflux.js"></script>
</head>
<body>
<div id="example"></div>
<script id="jsbin-javascript">
/*
https://github.com/spoike/refluxjs#using-the-listener-instance-methods
*/
// var action1 = Reflux.createAction(),
// action2 = Reflux.createAction(),
// action3 = Reflux.createAction(),
// join = Reflux.joinTrailing(action1,action2,action3);
// function hello(data){
// console.log('== hello ==');
// console.log(data);
// }
// Reflux.createStore().listenTo(join,hello);
// action1('a');
// action2('b');
// action3('c');
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var ActionFactory = (function () {
function ActionFactory() {
_classCallCheck(this, ActionFactory);
this.actions = {};
}
_createClass(ActionFactory, [{
key: 'createAction',
value: function createAction(model) {
this.actions[model] = Reflux.createAction();
return this.actions[model];
}
}, {
key: 'getAction',
value: function getAction(model) {
return !!this.actions[model] ? this.actions[model] : this.createAction(model);
}
}]);
return ActionFactory;
})();
var acF = new ActionFactory();
function hello(data) {
console.log('== ' + data + ' ==');
}
Reflux.createStore().listenTo(acF.getAction('msg'), hello);
acF.getAction('msg')('lol');
</script>
<script id="jsbin-source-javascript" type="text/javascript">/*
https://github.com/spoike/refluxjs#using-the-listener-instance-methods
*/
// var action1 = Reflux.createAction(),
// action2 = Reflux.createAction(),
// action3 = Reflux.createAction(),
// join = Reflux.joinTrailing(action1,action2,action3);
// function hello(data){
// console.log('== hello ==');
// console.log(data);
// }
// Reflux.createStore().listenTo(join,hello);
// action1('a');
// action2('b');
// action3('c');
class ActionFactory {
constructor(){
this.actions = {};
}
createAction(model) {
this.actions[model] = Reflux.createAction();
return this.actions[model];
}
getAction(model) {
return !!this.actions[model]
? this.actions[model]
: this.createAction(model)
;
}
}
var acF = new ActionFactory();
function hello(data){
console.log(`== ${data} ==`);
}
Reflux.createStore().listenTo(acF.getAction('msg'), hello);
acF.getAction('msg')('lol');</script></body>
</html>
/*
https://github.com/spoike/refluxjs#using-the-listener-instance-methods
*/
// var action1 = Reflux.createAction(),
// action2 = Reflux.createAction(),
// action3 = Reflux.createAction(),
// join = Reflux.joinTrailing(action1,action2,action3);
// function hello(data){
// console.log('== hello ==');
// console.log(data);
// }
// Reflux.createStore().listenTo(join,hello);
// action1('a');
// action2('b');
// action3('c');
'use strict';
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var ActionFactory = (function () {
function ActionFactory() {
_classCallCheck(this, ActionFactory);
this.actions = {};
}
_createClass(ActionFactory, [{
key: 'createAction',
value: function createAction(model) {
this.actions[model] = Reflux.createAction();
return this.actions[model];
}
}, {
key: 'getAction',
value: function getAction(model) {
return !!this.actions[model] ? this.actions[model] : this.createAction(model);
}
}]);
return ActionFactory;
})();
var acF = new ActionFactory();
function hello(data) {
console.log('== ' + data + ' ==');
}
Reflux.createStore().listenTo(acF.getAction('msg'), hello);
acF.getAction('msg')('lol');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment