Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal Rewrite #45

Closed
curran opened this issue Feb 9, 2018 · 1 comment
Closed

Minimal Rewrite #45

curran opened this issue Feb 9, 2018 · 1 comment

Comments

@curran
Copy link
Member

curran commented Feb 9, 2018

This library feels too heavy, with all the submodules, and some features like serialization that have not seen much use in practice. Proposed new API, inspired by https://observablehq.com :

Before:

var my = ReactiveModel()
  ("a") // Create the property "a" with no default value.
  ("b", function (a){
    return a + 1;
  }, "a");
})

After:

const model = reactiveModel({
  b: [a => a + 1, 'a']
})

Before:

function increment(x){ return x + 1; }
var my = ReactiveModel()
  ("a", 5) // Create the property "a" with a default value of 5.
  ("b", increment, "a")
  ("c", increment, "b");

After:

const increment = x => x + 1;
const model = reactiveModel({
  a: 5,
  b: [increment, 'a'],
  c: [increment, 'b']
})

Before:

function add(x, y){ return x + y; }

var my = ReactiveModel()
  ("c", 5)
  ("d", 10)
  ("e", add, ["c", "d"]);

After:

// An object will be used when more than one dependency,
// because long argument lists was a problem when using the library.
// In this project https://github.com/unhcr/dataviz-streamgraph-explorer
cosnt add = ({x, y}) => x + y;
const model = reactiveModel({
  c: 5,
  d: 10,
  e: [add, 'c, d']
})

Before:

var my = ReactiveModel()
  ("firstName")
  ("lastName");
my("fullName", function (firstName, lastName){
  return firstName + " " + lastName;
}, "firstName, lastName");
my.firstName("Jane").lastName("Smith");

After:

const model = reactiveModel({
  fullName: ({firstName, lastName}) => `${firstName} ${lastName}`
});

// Setting like this will let us propagate the changes synchronously,
// when setting multiple fields, not relying on requestAnimationFrame,
// which complicated the implementation unnecessarily.
model.set({
  firstName: 'Jane',
  lastName: 'Smith'
});
@curran curran closed this as completed in c64c13c Feb 13, 2018
@curran
Copy link
Member Author

curran commented Feb 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant