Installing Declarativas in Your Application

Installing

You can use nodejs and npm to grab the latest copy of declarativas to get going in seconds.

With npm or yarn

Open up your terminal, and do the usual:

$ npm install --save declarativas
# OR
$ yarn add declarativas

And bring it in your code:

index.js
import { render, c } from 'declarativas';

// Get your canvas from an HTML file.
const canvas = document.querySelector('canvas');

render(
  canvas.getContext('2d'),
  [
    c('clearRect', {
      x: 0,
      y: 0,
      width: canvas.width,
      height: canvas.height,
    }),
    c('strokeStyle', '#000'),
    c('rect', {
      x: 100,
      y: 100,
      width: 20,
      height: 20,
    })
  ]),
);

With a CDN

index.html
<!doctype html>
<html>
<body>
  <canvas></canvas>
  <!-- CDN Import -->
  <script type="javascript" src="https://unpkg.com/declarativas"></script>
  
  <!-- Code -->
  <script type="javascript">
    const { render, c } = window.declarativas;
    const canvas = document.querySelector('canvas');

    render(
      canvas.getContext('2d'),
      [
        c('clearRect', {
          x: 0,
          y: 0,
          width: canvas.width,
          height: canvas.height,
        }),
        c('strokeStyle', '#000'),
        c('rect', {
          x: 100,
          y: 100,
          width: 20,
          height: 20,
        })
      ]),
    );
  </script>
</body>
</html>

Last updated