This repository was archived by the owner on Jun 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 140
This repository was archived by the owner on Jun 16, 2020. It is now read-only.
How to attach state to renderer? #218
Copy link
Copy link
Open
Description
I have part table component, this component will use part_row component so lets imagine:
Part_row component:
State:
export default (part) => {
return hg.state({
part_number: hg.value(part.part_number),
part_type: hg.value(part.part_type),
description: hg.value(part.description),
quantity: hg.value(part.quantity),
suggested_quantity: hg.value(part.suggested_quantity),
unit_price: hg.value(part.unit_price),
total_list_price: hg.value(part.total_list_price)
})
}
Renderer:
export default (state) => {
return h('div.row.part', [
h('div.col-xs-2.part_number', state.part_number),
h('div.col-xs-1.part_type', state.part_type),
h('div.col-xs-2.description', state.description),
h('div.col-xs-1.quantity', h('input', { type: 'number', value: state.quantity })),
h('div.col-xs-2.suggested_quantity', state.suggested_quantity),
h('div.col-xs-2.unit_price', state.unit_price),
h('div.col-xs-2.total_list_price', state.total_list_price)
]);
}
Table component
State:
export default (opts) => {
return hg.state({
parts_list: opts.parts
})
}
And finally renderer:
export const part_table_renderer = (state) => {
return h('div#part_table', [
h('div.row.header', [
h('div.col-xs-2', 'PART NUMBER'),
h('div.col-xs-1', 'PART TYPE'),
h('div.col-xs-2', 'DESCRIPTION'),
h('div.col-xs-1', 'QUANTITY'),
h('div.col-xs-2', 'SUGGESTED QUANTITY'),
h('div.col-xs-2', 'UNIT PRICE (USD)'),
h('div.col-xs-2', 'TOTAL LIST PRICE (USD)')
]),
h('div.body', [
state.parts_list.map((part) => part_component_renderer(part));
])
}
Sooooo how to "connect" or "attach" in this pattern part state? I don understand that. Why I should create state for part_row component if I pass state to renderer. The only stupid solution what I can imagine would be
Table component
State:
export default (opts) => {
return hg.state({
part1: opts.parts[0]
part2: opts.parts[1]
part3: opts.parts[2]
part4: opts.parts[3]
part5: opts.parts[4]
})
}
Thanks for help :)
Regards
Metadata
Metadata
Assignees
Labels
No labels