Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gossi/ember-command
Integrate your Business Logic with Ember
https://github.com/gossi/ember-command
command cqs ember ember-addon emberjs
Last synced: 24 days ago
JSON representation
Integrate your Business Logic with Ember
- Host: GitHub
- URL: https://github.com/gossi/ember-command
- Owner: gossi
- License: other
- Created: 2021-03-25T12:25:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-15T11:56:25.000Z (4 months ago)
- Last Synced: 2024-09-30T06:02:32.168Z (about 1 month ago)
- Topics: command, cqs, ember, ember-addon, emberjs
- Language: TypeScript
- Homepage: https://gossi.github.io/ember-command/
- Size: 949 KB
- Stars: 17
- Watchers: 7
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Commands for Ember
Implementation of the
[Command](https://refactoring.guru/design-patterns/command) design pattern from
[C-Q-S](https://en.wikipedia.org/wiki/Command–query_separation) for ember.- Commands are a primitives to be passed around
- Commands are just functions
- Commands are composable of many functions (but stays a function)
- Commands can have/be a link (but stays a function)
- Use commands with `(fn)` and enjoy partial applications (because it stayed a
function)What you'll get:
- A `Command` class to extend from for your implementation
- A `LinkCommand` as syntactic sugar for creating a link (through [`ember-link`](https://github.com/buschtoens/ember-link))
- A `@command` decorator to connect your component with your command
- A `` component as your building block to attach your command to the UI
- The `` will accept a `Command`, an `@action` or a `(link)`
- The `` will render the correct HTML element to take care of
accessibility## Documentation
[Read the Documentation](https://gossi.github.io/ember-command/)
## Installation
Install `ember-command` with:
```sh
ember install ember-command
```## Usage
The idea for `ember-command` is clearly to [separate your business logic from
your UI](https://gossi.github.io/ember-command/why.html) by offering a couple of
mechanics to do that.### Actions
Write an action that invokes a service within a [single file
component](https://rfcs.emberjs.com/id/0779-first-class-component-templates).```gts
import { action } from 'ember-command';
import { on } from '@ember/modifier';const inc = action(({ services }) => () => {
services.counter.inc();
});const Counter =
+export default Counter;
```### Composing
Compose various commands together to form a primitive that can be passed around.
This works well in combination with
[`ember-link`](https://github.com/buschtoens/ember-link).Let's make a link and add tracking to it:
```gts
import { command, action, CommandElement } from 'ember-command';
import { link } from 'ember-link';const track = action(({ services }) => (event: string) => {
services.tracking.track(event);
});const HomeLink =
Homeexport default HomeLink;
```## Contributing
See the [Contributing](https://github.com/gossi/ember-command/CONTRIBUTING.md) guide for details.
## License
This project is licensed under the [MIT License](https://github.com/gossi/ember-command/LICENSE.md).