Alternatively, use esbuild
and tsc
through the CLI to generate both CJS and ESM outputs: https://dev.to/endel/nodejs-package-authors-please-support-both-cjs-and-esm-1oj3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
room.onStateChange.once(function() { | |
function registerCallbacksOnStructure (schemaInstance, path) { | |
const schema = schemaInstance['_definition'].schema; | |
for (let field in schema) { | |
const schemaType = typeof(schema[field]); | |
if (schemaType === "object") { | |
// on item added to collection | |
schemaInstance[field].onAdd(function (item, key) { | |
onItemAdd([...path, field], item, key); |
Hi everybody! Regarding the possible new schema callback API, so far this is what I could came up so far, feedback highly appreciated! Do let me know if you feel I need to clarify anything!
I understand this may be long and hard to grasp, I can provide a side-by-side comparison between the new API and previous one so you can clearly see the difference.
The new API would allow to create all the callbacks at once, after the connection with the room has been established (even on deep structures) - rather than binding callbacks as Schema instances that are created on-demand on the client-side.
class Point extends Schema {
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on: http://breinygames.blogspot.com/2011/07/random-map-generation.html | |
// Needs improvment: | |
// - It is possible with small rooms for it to not be closed (i.e. a wall tile missing) | |
// - Walls often double up (more room spacing?) | |
var RoomMaze = srm = { | |
generate: function(gridSize, minRoomSize, maxRoomSize, maxRooms) { | |
// 1) Create the grid | |
var grid = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local x = (y > 10) and "condition is true" or "condition is false" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
apps : [{ | |
name : 'my-app', | |
script : 'lib/index.js', | |
watch : false, | |
instances : 1, | |
exec_mode : 'fork', | |
env: { | |
NODE_ENV: 'development' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Playground link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=19&pc=49#code/C4TwDgpgBAKuEB4YD4oF4oDsIHcoAoA6YgQwCcBzAZwC4oTMQBtAXQEp1UYBuAKF4DGAGxJUqUAEoB7KQFsk6eo1QBvXlChVgJYBAD8dHuqhTMAYTIQdEfFLDAAlqdpKQHNRoC+vb4JFioAFkQaTkoCAAPXUwAE3FQ+RUYhwAzFIhLTGAAcQhsMgcBOi0CzApPVWNTCytdW3snTBcVLBJZCGLgUooAGighCAA3CCE6TABXWQAjDKhPd29fFPHMAUdTKBiIFIdsBUjouNh4BATkZHxjMhlZOEhDHqqG5zoABXI2iF0yKgQASSa2lWEDuiBQTAA5NVLNYISxkEwAAwsXjuHz8LY7bD4YIJPotTCfOgAIj+wCgOCkZAA1lQAITEvoDYajKAARjmbG4QA | |
type Type<T> = new (...args: any[]) => T; | |
class Room<T = any> { | |
state?: T; | |
onCreate(options: any) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Allow non-root node to use ports 80 (HTTP) and 443 (HTTPS) | |
sudo setcap 'cap_net_bind_service=+ep' $(which node) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const csv = require('csv-parser') | |
const fs = require('fs') | |
const patrons = []; | |
const GENEROUS_PLEDGE = 30; | |
const GENEROUS_LIFETIME = 200; | |
fs.createReadStream(process.argv[2]) | |
.pipe(csv()) | |
.on('data', (data) => patrons.push(data)) |
NewerOlder