Comments (1)
Yea, code-only components currently cannot reference and initialize view modules. It is a fundamental issue that view module instances are identified using the JavaScript HTMLElement and found by walking the ancestor chain. Initializing a new view module in the code control would thus break all references to the page view module from inside of any templates the control has. Our current solution is to not support ITemplate
in markup controls, and not support view modules in code-only controls.
That being said, you can use JsComponent
without view modules. You can register the component globally in any script using dotvvm.registerGlobalComponent
. Then reference the script using the RequiredResource
dotvvm.registerGlobalComponent("your-component-name", registerReactControl(... same as in view module $controls))
This will make the component available to all pages and, crucially, to the JsComponent
initialized from code. When using a global component in a page, you can add Global
property to the component to make sure it isn't overwritten by the module. I'll put this into the docs.
In case that doesn't suit your needs, if you require the view module for some reason, there are two other ways to work around it:
- Make your control a markup control. You can put into a library using embedded resources. This will make it
impossiblea bad idea to add ITemplate/any content properties to the control. - Explicitly use the module from the page. Option A is to simply find the nearest parent with the
Internal.ReferencedViewModuleInfoProperty
and copy it to the JsComponent:
jsComponent.SetValue(Internal.ReferencedViewModuleInfoProperty,
this.GetAllAncestors().Select(c => c.GetValue(Internal.ReferencedViewModuleInfoProperty)).First(i => i != null))
Or, if you want to make the code future-proof against us hopefully resolving the core issue, copy the Internal.ReferencedViewModuleInfoProperty
from the TreeRoot of the current compilation unit using this (as JsComponent does it):
[ApplyControlStyle]
public static void AddReferencedViewModuleInfoProperty(ResolvedControl control)
{
if (control.TreeRoot.TryGetProperty(Internal.ReferencedViewModuleInfoProperty, out var x))
{
var value = ((ResolvedPropertyValue)x).Value;
control.SetProperty(new ResolvedPropertyValue(Internal.ReferencedViewModuleInfoProperty, value));
}
}
and then access the property by calling this.GetValue(Internal.ReferencedViewModuleInfoProperty)
instead of the LINQ.
Same trick by the way applies to using NamedCommand
s from a code-only control (it's probably more useful for that given there is no global option)
from dotvvm.
Related Issues (20)
- Dictionary item retrieval binding throws although item exists. HOT 2
- dot:Label For property Html proper labelling of corresponding form fields
- Change behaviour of DotVVM02 warning for overrides
- Please support `DateOnly` params in constructors of sub view models or support it for MinDate property of the bp:DatePicker control HOT 6
- Support for "is {}", "is []", “is null” & “is not null” && "is enum_member/s" in DotVVM markup HOT 1
- Read only value for bp:DatePicker
- Renaming from view model to rename also in bindings from markup HOT 1
- Intellisense for extension methods in markup files in Visual Studio 2022 HOT 2
- UX problem with bp:DatePicker in specific state
- I keep encountering this DotVVM error when hitting ESC key after the bp:ModalDialog is already closed by custom buttons inside its markup HOT 1
- Add to GridView columns the equivalent of `NullDisplayText` property from WebForms HOT 3
- Aliasing enums in markup
- Selection controls do not function properly with SelectedValue of type `bool?` HOT 2
- bp:GridViewDateTimeColumn Filter is Buggy
- bp:GridViewCheckBoxColumn Filter Cannot be Cleared
- Support for `datalist` control
- Add support for IncludeInPage property to GridViewTextColumn
- `app.UseForwardedHeaders()` does not function correctly due to resource paths being computed only once
- Better client-side error when viewmodel fails to deserialize
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotvvm.