Marcisbee / radi

🌀Tiny (in size) front-end framework with no extra browser re-flows
https://radi.js.org
MIT License
948 stars 34 forks source link

Refactor #16

Closed rafaelklaessen closed 6 years ago

rafaelklaessen commented 6 years ago

This PR includes my refactor.

It does not implement @colshacol 's proposal for modularizing classes as I assumed he was going to implement it; but I'm willing to add it too should he not have time.

It's certainly not perfect, but it works and no longer relies on parsing view as strings and back to JS.

Differences from the original API

// Old
l(this.foo);
l(this.foo.bar);
l(this.foo + '!');

// New
l(component, 'foo');
l(component, 'foo', 'bar');
l(component, 'foo').process(value => value + '!');

// Conditions
l(component, 'foo').process(
  value => (value === 'World' ? <div>A</div> : <div>B</div>)
);

// Lists
l(component, 'users').process(users =>
  users.map(user => <span>{char}</span>)
);

See component.test.js for more examples.