How to use the elm-hot.inject function in elm-hot

To help you get started, we’ve selected a few elm-hot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github halohalospecial / atom-elmjutsu / lib / hot-reloader.js View on Github external
function sendModifiedFile(filePath, ws) {
  const fileContents = fs.readFileSync(filePath, {
    encoding: 'utf8',
  });
  if (fileContents.endsWith('(this));')) {
    // If we got the complete file, send the modified contents.
    const modifiedContents = elmHot.inject(fileContents);
    ws.send(
      JSON.stringify({
        type: 'fileChanged',
        contents: modifiedContents,
      })
    );
  } else {
    // Else, try again after a few milliseconds.
    setTimeout(() => {
      sendModifiedFile(filePath, ws);
    }, 100);
  }
}
github halohalospecial / atom-elmjutsu / lib / hot-reloader.js View on Github external
app.get('/build', (req, res) => {
      const filePath = untildify(decodeURI(req.query.path));
      let fileContents = null;
      try {
        fileContents = fs.readFileSync(filePath);
      } catch (err) {}
      if (fileContents) {
        const hotReloadingHost = atom.config.get('elmjutsu.hotReloadingHost');
        res.send(
          hotReloadingCode
            .replace('HOST', hotReloadingHost)
            .replace('PORT', this.server.address().port)
            .replace('FILE_PATH', filePath) +
            '\n' +
            elmHot.inject(fileContents)
        );
      } else {
        res.sendStatus(404);
      }
    });

elm-hot

Hot code swapping for Elm

MIT
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Popular elm-hot functions