choojs / choojs/choo

Best pattern to fetch data based on a path

Open
#447 16 comments 0 reactions 0 assignees View on GitHub
Type: Documentation Type: Question
Dominant language
JavaScript
Stars
6.8k
Forks
573
PR merge metrics
No merged PRs in 30d

Description

### Expected behavior

```javascript
var html = require('choo/html')
var choo = require('choo')

var app = choo()
app.use(productStore)
app.route('/product/:id', mainView)
app.mount('body')

function mainView (state, emit) {

return html`

product is ${state.product.name}



`
function pullData(){
emitter.emit('fetchProduct');
}
}

function productStore (state, emitter) {
emitter.on('fetchProduct', function () {
fetch('/product/'+state.params.id,function (product) {
state.product = product;
emitter.emit('render')
})
})
}
```
I was wondering if this is a good pattern in order to fetch some data when access some URL.

Contributor guide

Open the contributing guide

Research direction

Start with the app.route, mainView, and productStore entry points shown in the issue, and read how route parameters and store events are handled. Determine whether the requested pattern is documented or requires a framework change; done would require a clearly agreed approach, since the issue does not define a specific implementation or test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.