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

Usage patterns and library-author api design (for consumers of signals) #74

Open
NullVoxPopuli opened this issue Mar 30, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@NullVoxPopuli
Copy link
Collaborator

NullVoxPopuli commented Mar 30, 2024

For example, if we're creating an object that needs reactive access to data, we don't need to expose the underlying implementation -- we can rely on getters (and setters, if needed), to make signals behave like "just javascirpt properties".

In providing a reactive property to a class, Board, we can define a property, previous that just is reactive, because it delays the read of the signal until the read of the previous property.

Shown here, using the @signal decorator idea from the readme:

class Demo {
  @signal previous = ...;
  
  // a class method(tm)
  createBoard = (x, y) => {
    let state = this;
    return new Board(x, y, {
      get previous() {
        return state.previous; 
      }
    });
  };
}

or using signals directly, maybe, less tied to what I'm immediately working on:

import { Signal } from "signal-polyfill";

const previousSignal = new Signal.State(/* ... */);

return new Board(x, y, {
  get previous() {
    return previousSignal.get(); 
  }
});

With this approach, the API of Board doesn't need to change to support any style of signals.


So, I suppose, more generally, should we try to come up with a list of tips'n'things like this?

My worry, is that we'll give folks a sharp tool, and they'll leave sharp edges on their api boundaries (or other places!), which make broader usage of Signals (or rather the integration between JS Frameworks) potentially more difficult.

@littledan
Copy link
Member

Yes, let’s definitely document this stuff, while acknowledging the range of opinions on what the surface should look like (not picking sides).

@littledan littledan added the documentation Improvements or additions to documentation label Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants