Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "heatsync", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A module to watch and reload CommonJS Modules on modification and sync results with objects", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
# Heatsync | ||
This is a module to watch and reload JS Modules on modification and sync results with objects | ||
This is a module to watch and reload CommonJS Modules on modification and sync results with objects | ||
In applications which require high uptime and are constantly being worked on as the development process normally is, developers might find it necessary to reload modules and have their changes take effect immediately without restarting the application. Luckily, that's where Heatsync comes in. | ||
# Basic Usage | ||
```js | ||
const Heatsync = require("heatsync"); | ||
const sync = new Heatsync(); | ||
// Heatsync offers native-like module resolution, but without types for fs struct. | ||
// relative paths based on the file the function is being called will work. | ||
// absolute paths also work. | ||
const utils = sync.require("./utils.js"); | ||
// The require method also accepts an Array of IDs where IDs can be: | ||
// A relative path, an absolute path or a node_module name. | ||
const [file1, file2, file3] = sync.require([ | ||
"./epic.js", | ||
"./poggers.js", | ||
"../lib/controller.js" | ||
]); | ||
``` | ||
# How it works | ||
Object.assign and the delete keyword mutates the state of an Object. which means it doesn't replace the reference. You can assign values to an Object through Object.assign and the new/updated properties will appear in other files so long as you have the same reference. | ||
# Gachas | ||
You must be very careful with Sync.resync as it iterates over modules and their children recursively and drops the cache for them. If another module references a child mod that gets dropped and it's not being synced by heatsync, then multiple instances of the mod which may be outdated would still be held within memory and possibly wouldn't get swept. With this in mind, practice efficient memory management and if you must use resync, then make sure references would not hold stale copies of a mod. | ||
# Examples | ||
@@ -7,0 +32,0 @@ Code for an example can be found at example/ |
64137
46