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

[RFC] bean metadata extension capability #28

Open
foreleven opened this issue Aug 15, 2019 · 1 comment
Open

[RFC] bean metadata extension capability #28

foreleven opened this issue Aug 15, 2019 · 1 comment
Labels
feature_request RFC Request for comments
Milestone

Comments

@foreleven
Copy link
Collaborator

foreleven commented Aug 15, 2019

The stated meta-information extension capability of the stated-bean can be used to implement more functions. For example, the routing parameters and the stated field are automatically synchronized.

@StatedBean()
class A {
  @Stated()
  @RouteParam("name")
  a: string;
}
  1. When accessing the route /?name=test, the initial value of a will be set to test
  2. When the value of a changes, the route will be synchronized. /?name=test2

@RouteParam

const RouteParam = (name: string) => (target: Object, fieldKey: string) => {
   getMetadataStorage().collectExtension(Symbol.for('stated-bean-route-param'), ...);
}

StatedBeanMetaStorage

class StatedBeanMetaStorage {
  collectExtension(extensionName: string | symbol, extension: any) {
     ...
  }
}

StatedRouteInterceptor

class StatedRouteInterceptor implements StatedInterceptor {
  async stateInit(context: EffectContext, next: NextCaller) {
    // if with @RouteParam
    // get name value from route
    // context.setValue('test');
    await next();
  }

  async stateChange(context: EffectContext, next: NextCaller) {
    // if with @RouteParam
    const value = context.value;
    await next();
    // sync to router
  }
}
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label feature_request to this issue, with a confidence of 0.87. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@JounQin JounQin added this to the 1.0 milestone Aug 16, 2019
@JounQin JounQin added the RFC Request for comments label Aug 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature_request RFC Request for comments
Projects
None yet
Development

No branches or pull requests

2 participants