@gwenmohr/sensor-tiles
v1.0.6
Published
Algorithms for a geographical data visualization project that maps and interpolates sensor data onto a 2d tile matrix.
Downloads
6
Readme
sensor-tiles
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
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');
// ...
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');
// 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