-
-
Notifications
You must be signed in to change notification settings - Fork 33
Fix: handle nullish values in template sinks with ?? operator #49
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,7 +169,22 @@ export function rml(strings: TemplateStringsArray, ...expressions: RMLTemplateEx | |
| acc = accPlusString +expression.join(''); | ||
| } else { | ||
| // expression is a future or an object | ||
|
|
||
|
|
||
| if ( | ||
| expression && | ||
| typeof expression === 'object' && | ||
| 'value' in expression && | ||
| !isPromise(expression) && | ||
| !isObservable(expression) | ||
| ) { | ||
| const valueType = typeof expression.value; | ||
| if (['string', 'number', 'boolean'].includes(valueType)) { | ||
| acc = accPlusString + (expression.value ?? ''); | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
| // Future / Object Sink | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change block seems redundant. Everything works well with the other change alone.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. completed! |
||
| const nextString = strings[i+1]; | ||
| // if it's a BehaviorSubject or any other sync stream (e.g.: startWith operator), pick its initial/current value to render it synchronously | ||
| const initialValue = currentValue(expression.source ?? expression); | ||
|
|
@@ -268,7 +283,7 @@ export function rml(strings: TemplateStringsArray, ...expressions: RMLTemplateEx | |
| addRef(ref, isSinkBindingConfiguration(_source) ? _source : InnerHTML(_source)); | ||
| acc = acc | ||
| +(existingRef ? string : string.replace(/\s*>\s*$/, ` ${RESOLVE_ATTRIBUTE}="${ref}">`)) | ||
| +(initialValue || '') | ||
| +(initialValue ?? '') | ||
| ; | ||
|
|
||
| } else if(/>?\s*[^<]*$/m.test(string) && /^\s*[^<]*\s*<?/m.test(nextString)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are great, could you please move them inside the BehaviorSubject block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!