Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reactive-function

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reactive-function - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

28

index.js

@@ -31,3 +31,3 @@ var ReactiveProperty = require("reactive-property");

if(!property.id){
property.id = counter++;
property.id = String(counter++);
properties[property.id] = property;

@@ -47,3 +47,8 @@ }

var callback = options.callback;
var output = options.output || function (){};
var output = options.output;
if(!output){
output = function (){};
output.propertyName = "";
}

@@ -170,21 +175,10 @@ // This gets invoked during a digest, after inputs have been evaluated.

// Replace ids with names for nodes.
// Add property names.
serialized.nodes.forEach(function (node){
var name = properties[node.id].propertyName;
if(name){
node.id = name;
var propertyName = properties[node.id].propertyName;
if(typeof propertyName !== "undefined"){
node.propertyName = propertyName;
}
});
// Replace ids with names for links.
serialized.links.forEach(function (link){
var sourceName = properties[link.source].propertyName;
if(sourceName){
link.source = sourceName;
}
var targetName = properties[link.target].propertyName;
if(targetName){
link.target = targetName;
}
});
return serialized;

@@ -191,0 +185,0 @@ }

{
"name": "reactive-function",
"version": "0.10.0",
"version": "0.11.0",
"description": "A library for managing data flows and changing state.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -583,46 +583,91 @@ // Unit tests for reactive-function.

assert.equal(serialized.nodes[0].id, "fullName");
assert.equal(serialized.nodes[1].id, "firstName");
assert.equal(serialized.nodes[2].id, "lastName");
assert.equal(serialized.nodes[0].id, "56");
assert.equal(serialized.nodes[1].id, "57");
assert.equal(serialized.nodes[2].id, "58");
assert.equal(serialized.links[0].source, "firstName");
assert.equal(serialized.links[0].target, "fullName");
assert.equal(serialized.links[1].source, "lastName");
assert.equal(serialized.links[1].target, "fullName");
assert.equal(serialized.nodes[0].propertyName, "fullName");
assert.equal(serialized.nodes[1].propertyName, "firstName");
assert.equal(serialized.nodes[2].propertyName, "lastName");
assert.equal(serialized.links[0].source, "57");
assert.equal(serialized.links[0].target, "56");
assert.equal(serialized.links[1].source, "58");
assert.equal(serialized.links[1].target, "56");
rf.destroy();
});
// Holding off until https://github.com/datavis-tech/graph-data-structure/issues/12
//it("Should serialize the data flow graph, falling back to property ids.", function (){
it("Should serialize the data flow graph and omit property names if they are not present.", function (){
// var firstName = ReactiveProperty("Jane");
// var lastName = ReactiveProperty("Smith");
// var fullName = ReactiveProperty();
var firstName = ReactiveProperty("Jane");
var lastName = ReactiveProperty("Smith");
var fullName = ReactiveProperty();
var rf = ReactiveFunction({
inputs: [firstName, lastName],
output: fullName,
callback: function (first, last){
return first + " " + last;
}
});
// ReactiveFunction({
// inputs: [firstName, lastName],
// output: fullName,
// callback: function (first, last){
// return first + " " + last;
// }
// });
var serialized = ReactiveFunction.serializeGraph();
// var serialized = ReactiveFunction.serializeGraph();
assert.equal(serialized.nodes.length, 3);
assert.equal(serialized.links.length, 2);
// console.log(JSON.stringify(serialized, null, 2));
// These tests may easily break if earlier tests are modified.
// Fix by copying values from:
//console.log(JSON.stringify(serialized, null, 2));
// assert.equal(serialized.nodes.length, 3);
// assert.equal(serialized.links.length, 2);
assert.equal(serialized.nodes[0].id, "59");
assert.equal(serialized.nodes[1].id, "60");
assert.equal(serialized.nodes[2].id, "61");
// assert.equal(serialized.nodes[0].id, "fullName");
// assert.equal(serialized.nodes[1].id, "firstName");
// assert.equal(serialized.nodes[2].id, "lastName");
assert.equal(typeof serialized.nodes[0].propertyName, "undefined");
// assert.equal(serialized.links[0].source, "firstName");
// assert.equal(serialized.links[0].target, "fullName");
// assert.equal(serialized.links[1].source, "lastName");
// assert.equal(serialized.links[1].target, "fullName");
assert.equal(serialized.links[0].source, "60");
assert.equal(serialized.links[0].target, "59");
assert.equal(serialized.links[1].source, "61");
assert.equal(serialized.links[1].target, "59");
//});
rf.destroy();
});
it("Should serialize case without any output specified and use empty string as property name.", function (){
var a = ReactiveProperty(5);
var b = ReactiveProperty(10);
var sideEffect = 0;
var rf = ReactiveFunction({
inputs: [a, b],
callback: function (a, b){
sideEffect++;
}
});
// For serialization.
a.propertyName = "a";
b.propertyName = "b";
var serialized = ReactiveFunction.serializeGraph();
assert.equal(serialized.nodes.length, 3);
assert.equal(serialized.links.length, 2);
//console.log(JSON.stringify(serialized, null, 2));
assert.equal(serialized.nodes[0].id, "62");
assert.equal(serialized.nodes[1].id, "63");
assert.equal(serialized.nodes[2].id, "64");
assert.equal(serialized.nodes[0].propertyName, "");
assert.equal(serialized.nodes[1].propertyName, "a");
assert.equal(serialized.nodes[2].propertyName, "b");
assert.equal(serialized.links[0].source, "63");
assert.equal(serialized.links[0].target, "62");
assert.equal(serialized.links[1].source, "64");
assert.equal(serialized.links[1].target, "62");
rf.destroy();
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc