This is similar to GadgetRef <= operation, but works with a raw TypedTag and wraps it in a Gadget.
This is similar to GadgetRef <= operation, but works with a raw TypedTag and wraps it in a Gadget. This is used when you declared it with GadgetRef.of[].
Set this to the actual Gadget when it's created.
Set this to the actual Gadget when it's created.
If this reference was already rendered, this will render the new gadget and reparent it where the reference lives.
The same as <=, but doesn't remove the old value from the DOM.
The same as <=, but doesn't remove the old value from the DOM. Use this if you expect to reuse the Gadgets that you are assigning. (Typically when this reference is somehow modal, and you don't want to regenerate the Gadgets every time because they are expensive.)
We intercept applyTo() (which is part of Scalatags), to record the parent of this Node.
We intercept applyTo() (which is part of Scalatags), to record the parent of this Node.
The actual renderer for this reference.
The actual renderer for this reference.
If this reference has not yet been set, it will create and return an empty span.
TODO: this is type-anonymous -- it simply expects to return an Element. Can we do better?
Concrete subclasses should fill this in with the actual guts of the Gadget.
Fetches the actual rendered DOM Node for this Frag.
Fetches the actual rendered DOM Node for this Frag.
IMPORTANT: this is convenient, but fundamentally unsafe! Only use it in places where you are *certain* that the Node has already been rendered; otherwise, use the safer elemOpt or elemOptRx!
An Rx member containing the actual Node iff it has been rendered.
An Rx member containing the actual Node iff it has been rendered.
TODO: the semantics of flatMapNow() are, at best, questionable.
TODO: the semantics of flatMapNow() are, at best, questionable. This is trying to do too much, and should be renamed or scrapped.
Produces Rx[Some[T]] if the Gadget is ready, or Rx[None] if not.
Produces Rx[Some[T]] if the Gadget is ready, or Rx[None] if not.
The true boilerplate-killer.
The true boilerplate-killer. Takes an Rx to flatMap over -- that is, a function on the underlying Gadget that produces another Rx. *If* the Gadget is ready, it then applies function f to that Rx; otherwise, it produces the default.
Returns the underlying Gadget.
Returns the underlying Gadget. Use with care: this will throw if the Gadget hasn't been created yet!
Convenience wrapper for getting at the underlying element, if it's been set up yet.
Convenience wrapper for getting at the underlying element, if it's been set up yet.
Convenience function for operating on the Element, if this Gadget has been rendered.
Convenience function for operating on the Element, if this Gadget has been rendered.
Yes, this deliberately squashes Output to Element for purposes of the function call. That is typically good enough, and is kinder to the sQuery type inference.
TBD: this suggests that sQuery should be smarter about Element subclasses.
The safe way to run some code iff this Gadget actually exists.
The safe way to run some code iff this Gadget actually exists. This runs *immediately*, and does not produce an Rx.
Shorthand for this extremely common case.
Shorthand for this extremely common case.
This maps the given function over the underlying Gadget, when it exists.
This maps the given function over the underlying Gadget, when it exists. This returns a proper Rx.
Iff this Gadget is ready, produces the result of the expression; otherwise, produces the default.
Iff this Gadget is ready, produces the result of the expression; otherwise, produces the default.
Concrete Gadgets can override this to perform actions after we've created the actual Element.
Concrete Gadgets can override this to perform actions after we've created the actual Element.
Just delegate the insertion signal to the underlying Gadget, if there is one.
Just delegate the insertion signal to the underlying Gadget, if there is one.
Subclasses can override this to define behaviour that happens in the middle of the render function.
Subclasses can override this to define behaviour that happens in the middle of the render function. Generally used by infrastructure, not concrete classes.
The underlying Gadget that we're tracking here.
The underlying Gadget that we're tracking here. If you want to react to the Gadget's creation, or be safe when you aren't sure about creation order, observe this.
The parent of the resulting Node, once it has been created.
The parent of the resulting Node, once it has been created.
Reassigns the contents of this reference, rendering the new Gadget and putting it into place if needed.
Reassigns the contents of this reference, rendering the new Gadget and putting it into place if needed. This will only be called if something actually changes.
This is usually called via the <= or <~ operators.
Note that this requires a
TODO: there is a grungy asInstanceOf in here. Is there any way to pick up the actual type of the underlying Gadget without polluting the type signature of this call in such a way that you have to redundantly state it every time?
We intercept render (which is part of Scalatags), to record the Node when it gets created, and to provide access to the creation event.
We intercept render (which is part of Scalatags), to record the Node when it gets created, and to provide access to the creation event.
IMPORTANT: this imperatively renders the Gadget; if you call it repeatedly, it will render again! Use rendered by preference most of the time.
Lazy version of render().
Lazy version of render(). This returns the rendered content of the Gadget, rendering if need be. This allows you to easily fetch the elem repeatedly, without worrying about re-rendering.
Slam the element for this Gadget.
Slam the element for this Gadget. You should only call this iff the element was created from an external mechanism and you're building this Gadget around that element.
This is intentionally designed for chaining, for ease of use -- it returns this Gadget.
Invoke the given function when this Gadget is actually rendered.
Invoke the given function when this Gadget is actually rendered. At that point, the Gadget's elem has been set, so you can operate on it. This is sometimes the right place to add, eg, event hooks.
This defines a callback for when the Gadget actually gets defined.
This defines a callback for when the Gadget actually gets defined. Note that this does *not* mean that the underlying Element has been created! If you care about the underlying DOM element, use whenRendered() instead.
This function is chainable.
TBD: is this *ever* the right answer? We might consider deprecating this as a public entry point, since you usually want whenRendered() instead.
A variant of GadgetRef, which you should use when you're just dealing with a raw TypedTag, not a Gadget per se.
All this really does is provide type-safety for this situation, without requiring that GadgetRef itself know about T.
Create this using GadgetRef.of[].