1.0.12 • Published 4 years ago

@gwenmohr/sensor-tiles-js v1.0.12

Weekly downloads
13
License
ISC
Repository
github
Last release
4 years ago

sensor-tiles

npm.io npm version

Algorithms for our geographical data visualization project that maps and interpolates sensor data onto a 2D tile matrix.

Written in Purescript, targeting Javascript.

How to call from javascript

Installing with npm

Install the package as a dependency with npm

npm install --save-dev @gwenmohr/sensor-tiles-js

Now you have the choice between two ways of calling the library.

A: JS wrapper (Recommended)

To allow for idiomatic multi-parameter calls from javascript to our purescript code, we've written a javascript wrapper. It will also deep freeze all returned objects, making them completely immutable.

var Tiles = require ('@gwenmohr/sensor-tiles-js');

// ...

let w = 4;
let h = 6;

let tile_matrix = Tiles.init(w,h); // frozen

let sensor_x = 2;
let sensor_y = 3;
let sensor_value = 2.5

let with_sensor = Tiles.insertSensor(sensor_x, sensor_y, sensor_value, tile_matrix); // frozen

console.log(with_sensor);

B: Direct calls (Not recommended)

The compiled purescript code can also be called directly. Some precautions have to be taken to prevent possible errors in that case.

Immutability

You should treat all objects returned by the Tiles module as immutable if you plan to eventually pass them back to another function exposed by the module.

Immutability on the javascript side can be achieved by using the shallow freeze Object.freeze() or an appropriate deep freeze function. Read more about freezing objects and how to spin up a deep freeze function in the MDN web docs.

If you don't freeze the objects and mutate them manually, you risk breaking them.

Curried

By default, the exposed purescript functions are compiled to curried javascript functions, i.e. function parameters have to be applied one by one.

var Tiles = require ('@gwenmohr/sensor-tiles-js');
// curried functions are available under the PS (purescript) object
var TilesPS = Tiles.PS;

// ...

let w = 4;
let h = 6;

let tile_matrix = TilesPS.init(w)(h);
Object.freeze(tile_matrix)

let sensor_x = 2;
let sensor_y = 3;
let sensor_value = 2.5

let with_sensor = TilesPS.insertSensor(sensor_x)(sensor_y)(sensor_value)(tile_matrix);
Object.freeze(tile_matrix)

console.log(with_sensor);

Developers: How to build

# using your globally installed `spago` and `purs`
spago build

# using the recommended version of `spago` and `purs` from the npm dependencies
# run once
npm install
# run each build, (up to 50% faster than npm install)
npm run-script install
1.0.9

4 years ago

1.0.8

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.12

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago