Support multiple custom event namespaces#217
Open
thisispiers wants to merge 1 commit into
Open
Conversation
Owner
|
@thisispiers can you help me understand the use case here? Currently, components can listen to multiple signals and stores. let fname = signal('Chris', 'fname');
let greeting = signal('Hello', 'greeting');
function template () {
return `${greeting}, ${fname}!`;
}
component('#app', template, {
signals: ['fname', 'greeting'],
});What problem does this solve that isn't already addressed by the current API? |
Author
|
Sorry if I'm wasting your time. It was just an idea and I thought why not share it. It could be helpful to reduce renders for nested signals: const lists = reef.signal([], 'lists');
function newList() {
const list = reef.signal([], ['list', `list-${lists.length}`]);
lists.push(list);
}
reef.component('#total_lists', () => {
return `There are ${lists.length} lists`;
}, {
signals: ['lists'],
});
reef.component('#total_items', () => {
const total = Object.keys(lists).reduce((acc, i) => {
return acc += lists[i].length;
}, 0);
return `There are ${total} items in total`;
}, {
signals: ['list'],
});
reef.component('#third_list', () => {
if (typeof lists[2] === 'undefined') {
return `A third list does not exist`;
}
return `The third list contains ${lists[2].length} items`;
}, {
signals: ['list-2'],
});It could also be helpful to monitor all signal changes when debugging: document.addEventListener('reef:signal', console.debug); |
Owner
|
@thisispiers not a waste of time at all! I'm just trying to understand the use case before making any code changes. So I see the theoretical application you're going for here. I'm not sure it's the best code design. Do you have a real-world practical application for doing this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Emitting multiple events allows different components to listen to different event namespaces.
There is currently no type checking, sanitization or validation.