if (window.addEventListener) {
window.addEventListener("message", function (message) {
reciever.handleMessage(message); // <-вызов функции как метода объекта
});
}
var path = require('path');
var fs = require('fs');
var async = require('async');
function getFiles (dirPath, callback) {
fs.readdir(dirPath, function (err, files) {
if (err) return callback(err);
var filePaths = [];
async.eachSeries(files, function (fileName, eachCallback) {
var filePath = path.join(dirPath, fileName);
fs.stat(filePath, function (err, stat) {
if (err) return eachCallback(err);
if (stat.isDirectory()) {
getFiles(filePath, function (err, subDirFiles) {
if (err) return eachCallback(err);
filePaths = filePaths.concat(subDirFiles);
eachCallback(null);
});
} else {
if (stat.isFile() && /\.js$/.test(filePath)) {
filePaths.push(filePath);
}
eachCallback(null);
}
});
}, function (err) {
callback(err, filePaths);
});
});
}
getFiles('./', function (err, files) {
console.log(err || files);
});
.sidebar {
position:fixed;
top:0;
bottom:0;
left:0;
width: 250px;
padding:10px;
background-color: #cc0000;
color: #ffffff;
}
.content {
padding:10px;
margin-left: 260px;
}
var async = require('async');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'me',
password : 'secret',
database : 'my_db'
});
connection.connect();
async.auto({
users: function (cb) {
connection.query("SELECT `id`, `name`, `isDude` FROM `users`", function(err, rows) {
cb(err, rows);
});
},
handle: ['users', function (cb, results) {
async.forEachOfSeries(results.users, function (user, key, mapCb) {
if (user.isDude) return mapCb();
connection.query("UPDATE `users` SET `isDude`=1 WHERE `id`=?", [user.id], mapCb);
}, cb);
}]
}, function (err) {
if (err) {
console.error(err);
} else {
console.log('All users is dudes, bro!');
}
connection.end();
});
store_changeHandler (event) {
var Component = this.props.store.view;
this.setState({
component: (<Component />)
});
};
render() {
return <div>{this.state.component}</div>;
}
var players = {
uryBa10dquiRVP77AAAD: { id: 'uryBa10dquiRVP77AAAD', x: 200, y: 200 },
PPF6HbYRf3dm30w1AAAE: { id: 'PPF6HbYRf3dm30w1AAAE', x: 200, y: 200 }
};
var players = [
{ id: 'uryBa10dquiRVP77AAAD', x: 200, y: 200 },
{ id: 'PPF6HbYRf3dm30w1AAAE', x: 200, y: 200 }
];