question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal for changes to API

See original GitHub issue

This is a proposal for changes to the user facing API of Radi. It’s just a proposal, take it with a grain of salt.

  • Add support for extending Radi’s Component class rather than only being able to use component, eg:
class Counter extends Radi.Component {
  view() {
    return <h1>Foo</h1>
  }
}
  • Reuse the npm prop-types package to provide a type checking system for props.
  • Add a map callback to Listener, which would be a shortcut for mapping arrays, but it would also enable for more efficient list rendering in the future.
  • Separate actions, mixins, props and state. So not this.foo but this.state.foo.
  • Provide shortcuts to the l function. Pass a state and props function to view so that you can do state('foo') rather than l(component, 'state', 'foo'). Only makes sense if the point above is applied.

Let me know what you think! 😄

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:113 (57 by maintainers)

github_iconTop GitHub Comments

4reactions
harry-smcommented, Mar 24, 2018

My shallow proposal is purely syntactic sugar. Use decorators.

@Component()
class TestComponent {
  view() { return <h1>Foo Bar</h1>; }
}

The Action decorator is just for labeling.

@Component()
class TestComponent {
  view() { return <button onClick={this.someAction}>Click Me</button>; }

  @Action()
  someAction() { alert("I was clicked!"); }
}
3reactions
jpitcharducommented, Apr 12, 2018

So as a Summary

Issue Summary

Component Declaration

Extending Radi.Component

class TestComponent extends Radi.Component {
  view() {
    //...
  }

  state() {
    //...
  }
}

Using @Component decorator

@Component
class TestComponent {
  view() {
    // ...
  }

  @State
  state() {
    return { foo: "Foo" };
  }
}

State in the view

Having this.state.prop be listeners

  view(){
      <div>{this.state.foo}</div>
  }

Injecting a state function to the view

  view(state){
      <div>{state('foo')}</div>
  }

Injecting a state function to the view and use selectors

  view(state){
      <div>{state(snapshot => snapshot.foo)}</div>
  }

Using a listen function withing the component

  view() {
      <div>{this.listenState('foo')}</div>
  }

Remaining concerns

  • Typescript support
  • Immutable state

Am I missing something?

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Improvement Proposals: Google's Take on the API Style ...
API Improvement Proposals, or AIPs, are documents outlining Google's guidelines for API design. Most AIPs focus on universal design standards — ...
Read more >
API Change Proposals - Standard library developers Guide
The API Change Proposal process is intended to be a lightweight first step to getting new APIs added to the standard library. The...
Read more >
Identify, Edit, and Streamline API Collaboration with Proposals!
Proposals give you a quick overview of current changes to your APIs. You can now automatically surface in-flight API Design and Documentation ...
Read more >
API documentation proposal · WebPlatform Docs
Template and forms changes that need to be implemented; Priorities and project management; Additional documents. Current state of the WPD API documentation.
Read more >
Using Proposed API - Visual Studio Code
We give our best effort to avoid breaking API changes, and extension authors could ... <proposal>.d.ts to your project that uses @types/vscode ,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found