Skip to content

Instantly share code, notes, and snippets.

View igordata's full-sized avatar

igordata igordata

View GitHub Profile
@igordata
igordata / test.js
Last active September 15, 2020 21:37
promise fight
class Aaa {
loadTXs(txs, steps = 0) {
const rs = []
for (const tx of txs) {
const r = this._loadTX(tx)
if (r === null) continue
r.then((result) => {
this.$store.dispatch('rawDataAdd', result)
@igordata
igordata / server.js
Created November 4, 2018 11:11
How to cahce all pages with next.js
const express = require('express');
const next = require('next');
const LRUCache = require('lru-cache');
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({dev});
const handle = app.getRequestHandler();
// This is where we cache our rendered HTML pages
@igordata
igordata / link.jsx
Last active December 4, 2018 02:38
next.js link doesn't scroll to hash

#Сервисные сообщения имеют такое значение data._ messageService

##Юзер добавился в канал

  • _:"messageService"
  • action._: "messageActionChatAddUser"

Интересные поля:

  • action.users - массив с айдишниками людей, которые добавились. Обычно там только одна запись, но нужно предусмотреть и случай, когда их будет много.
@igordata
igordata / ww.js
Created February 10, 2018 14:08
centrifugo web worker
console.log('ww starting');
function wwsClass() {
var wws = this;
wws.tabs = [];
wws.onconnect = function (e) {
for (var i = e.ports.length; i--;) {
wws.tabs.push(new wwsTab(e.ports[i]));
}
console.log('New tabs ' + e.ports.length);
@igordata
igordata / rtm.js
Created February 10, 2018 14:08
centrifugo
function rtmClass() {
var rtm = this;
rtm.centrifuge = null;
rtm.worker = null;
/*
event handlers
*/
rtm.handlers = [];
rtm.on = function (event, handler) {
if (typeof rtm.handlers[event] === 'undefined') {
@igordata
igordata / jsonresponse.js
Created June 10, 2015 21:42
Standartified AJAX reply
const JSONResponse_STATUS_OK = 'OK', JSONResponse_STATUS_ERROR = 'ERROR';
/**
* JSONResponseParse
* @param text Unparsed text of server response
* @constructor
*/
function JSONResponseParse(text) {
try {
if (typeof text !== 'string') {
throw 'JSONResponse: Can\'t parse - not a string';