Class

org.querki.gadgets.core

GadgetElementRef

Related Doc: package core

Permalink

class GadgetElementRef[T <: Element] extends GadgetRef[Gadget[T]]

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[].

Linear Supertypes
GadgetRef[Gadget[T]], Gadget[Element], ManagedFrag[Element], Frag, Frag[Element, Node], Modifier[Element], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. GadgetElementRef
  2. GadgetRef
  3. Gadget
  4. ManagedFrag
  5. Frag
  6. Frag
  7. Modifier
  8. AnyRef
  9. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new GadgetElementRef()

    Permalink

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def <=[N](tag: TypedTag[T])(implicit arg0: GadgetNotifier[N]): GadgetElementRef[T]

    Permalink

    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[].

  4. def <=[N](g: Gadget[T])(implicit arg0: GadgetNotifier[N]): GadgetRef[Gadget[T]]

    Permalink

    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.

    Definition Classes
    GadgetRef
  5. def <~[N](tag: TypedTag[T])(implicit arg0: GadgetNotifier[N]): GadgetElementRef[T]

    Permalink
  6. def <~[N](g: Gadget[T])(implicit arg0: GadgetNotifier[N]): GadgetRef[Gadget[T]]

    Permalink

    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.)

    Definition Classes
    GadgetRef
  7. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def applyTo(parent: Element): Unit

    Permalink

    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.

    Definition Classes
    ManagedFrag → Frag → Modifier
  9. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  10. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  11. def createFrag: Element

    Permalink

    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?

    Definition Classes
    GadgetRefGadgetManagedFrag
  12. def doRender(): Nothing

    Permalink

    Concrete subclasses should fill this in with the actual guts of the Gadget.

    Concrete subclasses should fill this in with the actual guts of the Gadget.

    Note that this can be filled with a conventional Scalatags TypedTag thanks to an implicit conversion in globals.

    Definition Classes
    GadgetRefGadget
  13. def elem: Element

    Permalink

    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!

    Definition Classes
    ManagedFrag
  14. def elemOpt: Option[Element]

    Permalink
    Definition Classes
    ManagedFrag
  15. val elemOptRx: Var[Option[Element]]

    Permalink

    An Rx member containing the actual Node iff it has been rendered.

    An Rx member containing the actual Node iff it has been rendered.

    Definition Classes
    ManagedFrag
  16. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  17. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  18. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  19. def flatMapNow[T](f: (Gadget[T]) ⇒ Option[T]): Option[T]

    Permalink

    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.

    Definition Classes
    GadgetRef
  20. def flatMapRx[T](f: (Gadget[T]) ⇒ Rx[T])(implicit ctx: Owner): Rx[Option[T]]

    Permalink

    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.

    Definition Classes
    GadgetRef
  21. def flatMapRxOrElse[T, U](rx: (Gadget[T]) ⇒ Rx[T])(f: (T) ⇒ U, default: U)(implicit ctx: Owner): Rx[U]

    Permalink

    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.

    Definition Classes
    GadgetRef
  22. def foreachNow(f: (Gadget[T]) ⇒ Unit): Unit

    Permalink
    Definition Classes
    GadgetRef
  23. def get: Gadget[T]

    Permalink

    Returns the underlying Gadget.

    Returns the underlying Gadget. Use with care: this will throw if the Gadget hasn't been created yet!

    Definition Classes
    GadgetRef
  24. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  25. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  26. def isDefined: Boolean

    Permalink
    Definition Classes
    GadgetRef
  27. def isEmpty: Boolean

    Permalink
    Definition Classes
    GadgetRef
  28. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  29. def mapElemNow[T](f: (Element) ⇒ T): Option[T]

    Permalink

    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.

    Definition Classes
    GadgetRef
  30. def mapElementOrElse[R](default: R, f: (Element) ⇒ R): R

    Permalink

    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.

    Definition Classes
    Gadget
  31. def mapNow[T](f: (Gadget[T]) ⇒ T): Option[T]

    Permalink

    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.

    Definition Classes
    GadgetRef
  32. def mapNowOrElse[T](f: (Gadget[T]) ⇒ T, default: T): T

    Permalink

    Shorthand for this extremely common case.

    Shorthand for this extremely common case.

    Definition Classes
    GadgetRef
  33. def mapRx[T](f: (Gadget[T]) ⇒ T)(implicit ctx: Owner): Rx[Option[T]]

    Permalink

    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.

    Definition Classes
    GadgetRef
  34. def mapRxOrElse[T](f: (Gadget[T]) ⇒ T, default: T)(implicit ctx: Owner): Rx[T]

    Permalink

    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.

    Definition Classes
    GadgetRef
  35. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  36. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  37. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  38. def onCreate(elem: Element): Unit

    Permalink

    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.

    Definition Classes
    Gadget
  39. def onInserted(): Unit

    Permalink

    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.

    Definition Classes
    GadgetRefManagedFrag
  40. def onRendered(e: Element): Unit

    Permalink

    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.

    Definition Classes
    GadgetManagedFrag
  41. val opt: Var[Option[Gadget[T]]]

    Permalink

    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.

    Definition Classes
    GadgetRef
  42. def parentOpt: Option[Element]

    Permalink
    Definition Classes
    ManagedFrag
  43. val parentOptRx: Var[Option[Element]]

    Permalink

    The parent of the resulting Node, once it has been created.

    The parent of the resulting Node, once it has been created.

    Definition Classes
    ManagedFrag
  44. def reassign[N](g: Gadget[T], retainPrevious: Boolean)(implicit arg0: GadgetNotifier[N]): GadgetElementRef.this.type

    Permalink

    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?

    Definition Classes
    GadgetRef
  45. def render: Element

    Permalink

    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.

    Definition Classes
    ManagedFrag → Frag → Frag
  46. def rendered: Element

    Permalink

    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.

    Definition Classes
    ManagedFrag
  47. def setElem(e: Element): GadgetElementRef.this.type

    Permalink

    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.

    Definition Classes
    ManagedFrag
  48. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  49. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  50. def underlyingTag: ManagedFrag[Element]

    Permalink
    Definition Classes
    Gadget
  51. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  52. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  53. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  54. def whenRendered(f: (Gadget[T]) ⇒ Unit)(implicit ctx: Owner): GadgetElementRef.this.type

    Permalink

    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.

    Definition Classes
    GadgetRef
  55. def whenSet(f: (Gadget[T]) ⇒ Unit)(implicit ctx: Owner): GadgetElementRef.this.type

    Permalink

    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.

    Definition Classes
    GadgetRef

Inherited from GadgetRef[Gadget[T]]

Inherited from Gadget[Element]

Inherited from ManagedFrag[Element]

Inherited from Frag

Inherited from Frag[Element, Node]

Inherited from Modifier[Element]

Inherited from AnyRef

Inherited from Any

Ungrouped