Skip to content

Instantly share code, notes, and snippets.

Noitidart Noitidart

Block or report user

Report or block Noitidart

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View lib-sockets.js
import io from 'socket.io-client';
import getBaseUrl from '../../../utils/get-base-url';
let mSocket: null | SocketIOClient.Socket = null;
let mIsConnecting = false;
/**
* Create io.socket if it doesn't exist. If it does, and it's disconnected
* then reconnect it. If io.socket is in process of connecting, this will
View rxjs learnings.md
View sails-sockets-utils.js
/**
* Returns the room names that a socket is connected to.
*
* @param {string} socketId - a socket id - `sails.sockets.getId(this.req)`
*
* @returns {string[]} rooms
*/
function getSocketRooms(socketId) {
return new Promise((resolve, reject) => {
sails.io.of('/').adapter.clientRooms(socketId, (err, rooms) => {
View article-new.md
  1. Initialize sails web app by doing sails new sails-webpack and then Choose 1 for “Web App”.
  2. Uninstall Grunt: a. Run npm un grunt sails-hook-grunt. b. Delete /tasks directory.
  3. Install packages for our webpack hook: a. Install dev dependency by running npm i webpack -D. b. Install lodash as prod dependency (as I'm sure you'll use this in prod later) by running npm i lodash.
  4. Create webpack hook: a. Run sails generate hook webpack, this creates file api/hooks/webpack/index.js. b. Overwrite it with this contents - https://gist.github.com/Noitidart/e1a674f9b6dfcd8219baab1e6bce7b04
View index.js
import '../dependencies/bootstrap-4/bootstrap-4.css';
import '../dependencies/fontawesome.css';
import '../styles/importer.less';
import './cloud.setup';
import './components/ajax-button.component';
import './components/ajax-form.component';
import './components/js-timestamp.component';
import './components/modal.component';
import './utilities/open-stripe-checkout';
View layout-js.html
<script src="/dependencies/jquery.min.js"></script>
<script src="/dependencies/lodash.js"></script>
<script src="/dependencies/moment.js"></script>
<script src="/dependencies/bootstrap-4/bootstrap-4.bundle.js"></script>
<script src="/dependencies/cloud.js"></script>
<script src="/dependencies/vue.js"></script>
<script src="/dependencies/vue-router.js"></script>
<script src="/dependencies/sails.io.js"></script>
<script src="/dependencies/parasails.js"></script>
<script src="/js/index.bundle.js"></script>
View layout-css.html
<link rel="stylesheet" href="/js/index.bundle.css">
View .babelrc
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-transform-runtime"]
}
View webpack.js
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
module.exports.webpack = {
config: [
{
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devtool: process.env.NODE_ENV === 'production' ? undefined : 'eval-source-map',
entry: './assets/js/index.js',
View webpack.js
const webpack = require('webpack');
const { once } = require('lodash');
/**
* webpack hook
*
* If production, build once, then trigger `done`.
* If dev, build once, trigger `done`, then watch for changes to trigger rebuild.
*
* @description :: A hook definition. Extends Sails by adding shadow routes, implicit actions, and/or initialization logic.
You can’t perform that action at this time.