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

Introduce useHelper, update automation blueprint #144

Merged
merged 7 commits into from
Aug 29, 2021

Conversation

NullVoxPopuli
Copy link
Owner

@NullVoxPopuli NullVoxPopuli commented Aug 21, 2021

  • useHelper - invoke legacy ember helpers (non-functions) in js

  • shared - sharing a single invocation / value between components

    NOTE: this utility has moved to its own addon and will not be a part of ember-resources, as it made more sense to implement it as a decorator. Here is the repo: https://github.com/NullVoxPopuli/ember-shared-memory

    proposed api

    import Component from '@glimmer/component';
    import { useTask, shared } from 'ember-resources';
    
    export default class MyComponent extends Component {
       // reactive & derived ember-concurrency task
       // this could also just be _any_ resource
      compute = useTask(this, ...);
    
      // as long as only `data` is accessed (instead of `compute`), the value of `compute` will be shared among
      // all instances of MyComponent.
      //
      // this is still the same as instead defining this on a service and accessing that service from the component,
      // except: you don't need to define a service.
      // 
      data = shared(this, () => this.compute); 
    } 

    how does shared know what to key off of?

    • the class via this.constructor
    • the resource/task/function via prototype or some related means (tbd)

    this has the advantage over MemoizedTask in https://github.com/CrowdStrike/ember-resource-tasks in that we don't need to specify a key, and the api is much simplified.

This is a light wrapper around the built-in `invokeHelper` API
(which also is what powers the other resources).

```js
import someHelper from 'app-name/helpers/my-helper';
import { useHelper } from 'ember-resources';

export default class MyComponent extends Component {
  @Tracked count = 0;

  myHelper = useHelper(this, someHelper, () => [this.count]);
}
```
```hbs
{{this.myHelper.value}}
```
@NullVoxPopuli NullVoxPopuli changed the title Additional utilities Introduce useHelper, update automation blueprint Aug 29, 2021
@NullVoxPopuli NullVoxPopuli merged commit dc638ac into main Aug 29, 2021
@NullVoxPopuli NullVoxPopuli deleted the additional-utilities branch August 29, 2021 17:34
@github-actions
Copy link
Contributor

🎉 This PR is included in version 3.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

1 participant