DEV Community

Cover image for Glimmer DSL for SWT 4.20.0.0 - Time to Shine!!!
Andy Maleh
Andy Maleh

Posted on • Edited on

1 1

Glimmer DSL for SWT 4.20.0.0 - Time to Shine!!!

Alt Text

require 'glimmer-dsl-swt'

class HelloComputed
  class Contact
    attr_accessor :first_name, :last_name, :year_of_birth

    def initialize(attribute_map)
      @first_name = attribute_map[:first_name]
      @last_name = attribute_map[:last_name]
      @year_of_birth = attribute_map[:year_of_birth]
    end

    def name
      "#{last_name}, #{first_name}"
    end

    def age
      Time.now.year - year_of_birth.to_i
    rescue
      0
    end
  end

  include Glimmer::UI::CustomShell

  before_body {
    @contact = Contact.new(
      first_name: 'Barry',
      last_name: 'McKibbin',
      year_of_birth: 1985
    )
  }

  body {
    shell {
      text 'Hello, Computed!'

      composite {
        grid_layout {
          num_columns 2
          make_columns_equal_width true
          horizontal_spacing 20
          vertical_spacing 10
        }

        label {text 'First &Name: '}
        text {
          text <=> [@contact, :first_name]
          layout_data {
            horizontal_alignment :fill
            grab_excess_horizontal_space true
          }
        }

        label {text '&Last Name: '}
        text {
          text <=> [@contact, :last_name]
          layout_data {
            horizontal_alignment :fill
            grab_excess_horizontal_space true
          }
        }

        label {text '&Year of Birth: '}
        text {
          text <=> [@contact, :year_of_birth]
          layout_data {
            horizontal_alignment :fill
            grab_excess_horizontal_space true
          }
        }

        label {text 'Name: '}
        label {
          text <= [@contact, :name, computed_by: [:first_name, :last_name]]
          layout_data {
            horizontal_alignment :fill
            grab_excess_horizontal_space true
          }
        }

        label {text 'Age: '}
        label {
          text <= [@contact, :age, on_write: :to_i, computed_by: [:year_of_birth]]
          layout_data {
            horizontal_alignment :fill
            grab_excess_horizontal_space true
          }
        }
      }
    }
  }
end

HelloComputed.launch
Enter fullscreen mode Exit fullscreen mode

No, you are not hallucinating!!! The uses of <=> and <= to denote bidirectional (two-way) and unidirectional (one-way) data-binding respectively are real code from the updated Hello, Computed! sample working in Glimmer DSL for SWT 4.20.0.0, thanks to the new Shine syntax for View/Model Attribute Mapping and Ruby's ultra-malleable DSL syntax support.

The Glimmer DSL for SWT 4.20.0.0 major release ships with a number of innovations such as:

  • The new Shine data-binding syntax (early alpha feature)
  • SWT 4.20
  • Experimental support for AARCH64 CPU architectures courtesy of the new SWT 4.20
  • JRuby default version of 9.2.19.0
  • Tweaked samples to utilize the Shine syntax wherever possible

Happy Glimmering!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay