Extends
Members
auto :boolean
- Description:
- The auto attribute of this fragment, toggles automatic behaviour on/off
- Source:
- Overrides:
The auto attribute of this fragment, toggles automatic behaviour on/off
Type:
raw :string
- Description:
- The raw representation of this fragment, can be used to set/get the raw value.
- Source:
- Overrides:
The raw representation of this fragment, can be used to set/get the raw value.
Type:
Examples
//Get the raw value of a fragment
let fragmentValue = myFragment.raw;
//Set the raw value of a fragment
myFragment.raw = myNewFragmentValue;
(readonly) type :string
- Description:
- The type of this fragment
- Source:
- Overrides:
The type of this fragment
Type:
Methods
getDomPath()
- Description:
- Returns a dompath for finding this fragment
- Source:
- Overrides:
isUniqueModules() → {boolean}
- Description:
- Whether require() must produce a fresh module instance on every call ("unique modules").
Defaults to true, returning new modules every time. Adding the boolean "module" attribute
to the code-fragment element opts this fragment into shared modules instead: require()
reuses the cached module instance while its code is unchanged, and identical code maps
to the same data: module URL so the browser module map can cache the evaluation.
The attribute is presence-based like "auto"; module="false" is also honoured as an
explicit opt-out back to unique modules.
- Source:
Example
<code-fragment module data-type="text/javascript+babel" name="MyFragment">...</code-fragment>
Returns:
true if every require() must produce a fresh module instance
-
Type
-
boolean
registerOnAutoChangedHandler(callback)
- Description:
- Register a callback to run when auto attribute changes on fragment
- Source:
- Overrides:
Example
Fragment.one("#myFragment").registerOnAutoChangedHandler((fragment, auto)=>{
//Fragment auto attribute changed
});
Parameters:
registerOnClassChangedHandler(callback)
- Description:
- Register a callback to run when the classes of this fragment changes
- Source:
- Overrides:
Example
Fragment.one("#myFragment").registerOnClassChangedHandler((classes)=>{
//Some classes changed on this fragment
});
Parameters:
registerOnFragmentChangedHandler(callback)
- Description:
- Register a callback to be run when this fragments content changes.
- Source:
- Overrides:
Example
Fragment.one("#myFragment").registerOnFragmentChangedHandler((context)=>{
//Fragment has changed
});
Parameters:
registerOnFragmentUnloadedHandler(callback)
- Description:
- Register a callback to run when this fragment is unloaded
- Source:
- Overrides:
Example
Fragment.one("#myFragment").registerOnFragmentUnloadedHandler(()=>{
//Fragment is unloaded
});
Parameters:
registerOnTextDeletedHandler(callback)
- Description:
- Register a callback to run when text is deleted from this fragment
- Source:
- Overrides:
Example
Fragment.one("#myFragment").registerOnTextDeletedHandler((position, value)=>{
//Text "value" has been deleted from this fragment at "position"
});
Parameters:
registerOnTextInsertedHandler(callback)
- Description:
- Register a callback to run when text is inserted into this fragment
- Source:
- Overrides:
Example
Fragment.one("#myFragment").registerOnTextInsertedHandler((position, value)=>{
//Text "value" has been inserted into this fragment at "position"
});
Parameters:
(async) require() → {Promise.<Object>}
- Description:
- Evaluates the JavaScript code inside this fragment and returns the export object
- Source:
- Overrides:
Example
let exportedObject = Fragment.one("#myJSFragment").require();
Returns:
-
Type
-
Promise.<Object>
unRegisterOnAutoChangedHandler(callback)
- Description:
- Unregister a callback handler
- Source:
- Overrides:
Parameters:
unRegisterOnFragmentChangedHandler(callback)
- Description:
- Unregister a callback handler
- Source:
- Overrides:
Parameters:
unRegisterOnFragmentUnloadedHandler(callback)
- Description:
- Unregister a callback handler
- Source:
- Overrides:
Parameters:
unload()
- Description:
- Tell this fragment to unload itself
- Source:
- Overrides:
Example
Fragment.one("#myFragment").unload();