< Return to Video

RailsConf 2014 - The Power of M by Charles Lowell

  • 0:17 - 0:18
    CHARLES LOWELL: All right everybody.
  • 0:18 - 0:21
    Thank you so much for coming. I'm really,
  • 0:21 - 0:24
    I'm really honored. This morning we're gonna
  • 0:24 - 0:28
    be talking about client-side UI. These are,
  • 0:28 - 0:30
    this, your client that's, that's running inside
  • 0:30 - 0:33
    the browser. Not in the server. And some of
    you
  • 0:33 - 0:36
    might already be doing this a lot. Some of
    you
  • 0:36 - 0:40
    maybe a little. But wherever you fall along
    that
  • 0:40 - 0:42
    spectrum, you're going to be doing more of
    it,
  • 0:42 - 0:45
    chances are, as time, as time goes on, and
    not
  • 0:45 - 0:48
    less of it. And so I want, my goal here is
    to
  • 0:48 - 0:51
    share with you some of the ways that I've
    come
  • 0:51 - 0:54
    to think about clients, UIs, that can help
    you
  • 0:54 - 1:00
    build user interfaces that reactive, that
    are
  • 1:00 - 1:03
    educational and ultimately satisfying to your
    users.
  • 1:03 - 1:06
    What I want to share with you is the power
    of m.
  • 1:06 - 1:11
    My name is Charles. I'm cowboyd on GitHub
    and
  • 1:11 - 1:14
    Twitter, and I work at the Front Side, where
  • 1:14 - 1:20
    we've been doing UI for almost ten years,
    exclusively.
  • 1:20 - 1:23
    And when I talk about m, of course I'm
  • 1:23 - 1:26
    talking about m as in MVC. We're all familiar,
  • 1:26 - 1:30
    we've probably heard about the MVC pattern,
    model-view-controller. It's
  • 1:30 - 1:36
    what underpins all UIs. At least ostensibly.
  • 1:36 - 1:40
    But it can actually be pretty notoriously
    difficult to
  • 1:40 - 1:45
    pin down what, exactly, is MVC. It's a difficult
  • 1:45 - 1:49
    question, and if you ask two people, you're
    likely
  • 1:49 - 1:55
    to get a very different answer. And my, what
  • 1:55 - 1:59
    I'm. I don't want to, to, to go in
  • 1:59 - 2:03
    too much to try and define, give you one
  • 2:03 - 2:07
    particular version of MVC. I think there are
    many.
  • 2:07 - 2:10
    And, in fact, you find people asking the question,
  • 2:10 - 2:12
    is Rails MVC?
  • 2:12 - 2:15
    And some people are really, really stodgy
    about this.
  • 2:15 - 2:20
    They're, Rails MVC - pshaw. I'm more relaxed
    about
  • 2:20 - 2:24
    it. I say yes. Rails is MVC. It's server-side
  • 2:24 - 2:29
    MVC. It's a flavor of, of MVC. But what
  • 2:29 - 2:32
    I've come to realize is that MVC is, it's
  • 2:32 - 2:35
    kind of like Kung-Fu. There's lots of different
    schools.
  • 2:35 - 2:38
    There's lots of different ways to, to practition.
    Each
  • 2:38 - 2:41
    with its own strengths, each with its own
    weaknesses,
  • 2:41 - 2:44
    and, you know, which one you choose, you need
  • 2:44 - 2:48
    to, is, is, needs to be appropriate for the
  • 2:48 - 2:50
    context.
  • 2:50 - 2:54
    But today we're gonna be talking about client-side
    UI,
  • 2:54 - 2:56
    which is different than, different than the,
    than the
  • 2:56 - 3:01
    server-side MVC, and one of the things that,
    that
  • 3:01 - 3:02
    really sets it apart is, when you're working
    on
  • 3:02 - 3:05
    the client, you constantly have to manage
    state. The
  • 3:05 - 3:07
    client's always on. It's not like a Rails
    application
  • 3:07 - 3:09
    where you're basically setting up the world
    and then
  • 3:09 - 3:12
    throwing it away with every request. On the
    client,
  • 3:12 - 3:16
    you're always on. And so you have values that
  • 3:16 - 3:17
    relate to each other, and when one of those
  • 3:17 - 3:21
    values changes, you have to update the, the,
    the
  • 3:21 - 3:25
    other values to reflect that.
  • 3:25 - 3:32
    So, when we're thinking about MVC, I've come
    to,
  • 3:33 - 3:35
    to realize that really what you want to do
  • 3:35 - 3:39
    is you want to focus on the model. When
  • 3:39 - 3:42
    you first come to the, to the acronym, MVC,
  • 3:42 - 3:47
    model-view-controller, you tend to, to give
    equal billing to
  • 3:47 - 3:51
    the letters, because they're, they're, there's,
    no one is
  • 3:51 - 3:57
    set apart from, in, in the acronym. But I've
  • 3:57 - 4:00
    come to find that while the view and the
  • 4:00 - 4:04
    controller are important, they orbit the model.
  • 4:04 - 4:08
    So, I actually draw inspiration from, from
    this guy.
  • 4:08 - 4:10
    This is Plato. He's one of the ancient software
  • 4:10 - 4:12
    developers. You can actually tell. He's got
    a ChromeBook
  • 4:12 - 4:16
    Pixel there in his, in his hand.
  • 4:16 - 4:19
    And I think that he made an analogy, long
  • 4:19 - 4:23
    time ago, that I think really, cleanly captures
    this
  • 4:23 - 4:27
    concept. He had this allegory of a cave, and
  • 4:27 - 4:32
    the idea is that living in this world is,
  • 4:32 - 4:36
    is like being inside a cave, and back up
  • 4:36 - 4:38
    at the entrance of the cave, where you can't
  • 4:38 - 4:43
    see, there's this fire burning. And shapes
    pass in
  • 4:43 - 4:45
    front of the fire, and they cast shadows on
  • 4:45 - 4:48
    the wall. And we, inside the world, the only
  • 4:48 - 4:51
    thing that we can actually see is the shadows.
  • 4:51 - 4:55
    The shapes and the fire are hidden from us.
  • 4:55 - 4:56
    But if we look at the, the, the shadows,
  • 4:56 - 4:59
    we can extrapolate those shapes, and the shapes
    that
  • 4:59 - 5:02
    we see on the wall take their form purely
  • 5:02 - 5:05
    as a function of the shape in front of
  • 5:05 - 5:07
    the fire. They are as they are and are
  • 5:07 - 5:12
    no other way because, because of those true
    forms
  • 5:12 - 5:16
    and then the way that they interact.
  • 5:16 - 5:19
    And so this is all, this is all very,
  • 5:19 - 5:22
    very abstract. We've covered, you know, who
    I am.
  • 5:22 - 5:26
    We've covered the, the, an ancient philosopher,
    which I
  • 5:26 - 5:31
    guess is obligatory. But, I really want to
    give
  • 5:31 - 5:34
    a demonstration of this principle in action
    so that
  • 5:34 - 5:38
    you can see a little bit more concretely what
  • 5:38 - 5:40
    it is that I'm talking about. And so, to
  • 5:40 - 5:44
    do this, we're going to explore the concept
    of
  • 5:44 - 5:48
    a color. It's a, a, a very simple concept.
  • 5:48 - 5:50
    It's something that most of us can perceive
    very
  • 5:50 - 5:53
    easily. We, we, we know what it is, but
  • 5:53 - 5:57
    can be surprisingly difficult to, to pin down.
  • 5:57 - 6:01
    There's many, many, many different ways to
    represent it.
  • 6:01 - 6:04
    But we're gonna have, we're gonna have a color,
  • 6:04 - 6:06
    and this is gonna serve as the basic value
  • 6:06 - 6:07
    in our system. You can think of it as
  • 6:07 - 6:10
    like, an integer value or a string value,
    or,
  • 6:10 - 6:12
    or something like that, and we're going to
    see
  • 6:12 - 6:15
    how this when, when we have this color, what
  • 6:15 - 6:17
    kind of, what kind of reflections we can make
  • 6:17 - 6:19
    on that wall.
  • 6:19 - 6:23
    So, the first example is we're just going
    to,
  • 6:23 - 6:24
    we're just going to project this color onto
    a
  • 6:24 - 6:29
    single div. We're going to list this color
    value
  • 6:29 - 6:30
    on the right. We're going to be able to
  • 6:30 - 6:33
    set a color, remove a color, set a color,
  • 6:33 - 6:37
    and as we do that, the, the, the swatch,
  • 6:37 - 6:39
    the color swatch will, will update itself.
    And I
  • 6:39 - 6:44
    actually have a little demo here. And I've
    got
  • 6:44 - 6:46
    it hard-coded, just statically, so that when
    I check
  • 6:46 - 6:50
    this checkbox, the, the swatch will turn green.
    And
  • 6:50 - 6:52
    I can uncheck it and check it.
  • 6:52 - 6:55
    It's not, not too much. It's simple but it's
  • 6:55 - 6:58
    surprisingly satisfying. When I was putting
    this talk together
  • 6:58 - 7:01
    I actually would just sit there and click
    on,
  • 7:01 - 7:04
    off. It's great.
  • 7:04 - 7:05
    And you can do the same thing. We can
  • 7:05 - 7:09
    actually connect one color to two swatches.
    So we've
  • 7:09 - 7:12
    got, there's no reason we can't, can't duplicate
    that.
  • 7:12 - 7:15
    We'll take two of these swatches and, and
    bind
  • 7:15 - 7:18
    them to the, the, the same color. The, there's,
  • 7:18 - 7:20
    there's, so there's only one color in the
    system,
  • 7:20 - 7:23
    but the effect is the same.
  • 7:23 - 7:30
    Again, I could do that forever.
  • 7:30 - 7:31
    And this is what data binding is. You might
  • 7:31 - 7:35
    hear about data binding, and most people kind
    of
  • 7:35 - 7:38
    equate data binding with templates, because
    that's usually where
  • 7:38 - 7:39
    we come to it first, right. We change this
  • 7:39 - 7:41
    one value and the string value updates, right.
    But
  • 7:41 - 7:44
    templates are really just a special case of
    data
  • 7:44 - 7:49
    binding. In the abstract, it's really just
    about taking
  • 7:49 - 7:52
    two values and putting, putting them together
    so that
  • 7:52 - 7:55
    they occupy the same space in your application.
    There
  • 7:55 - 7:59
    really is no difference, conceptually, between
    them.
  • 7:59 - 8:03
    Some, this is, this is different than observation,
    which
  • 8:03 - 8:05
    is kind of another pillar on which client-side
    UIs
  • 8:05 - 8:08
    are built, where you can observe for value
    changes
  • 8:08 - 8:11
    in a model, and when that value changes you
  • 8:11 - 8:17
    get a callback. But. With data binding, you
    really
  • 8:17 - 8:20
    need to think of it taking two separate properties
  • 8:20 - 8:23
    and really just making them overlap and becoming
    the,
  • 8:23 - 8:25
    the absolute, the, the same thing.
  • 8:25 - 8:28
    Now, it is built on observation. So, when
    we
  • 8:28 - 8:30
    have a model and it's got some property. I've
  • 8:30 - 8:31
    got one named a and one named b. We
  • 8:31 - 8:37
    can use observers to, to, to implement the
    data
  • 8:37 - 8:41
    binding, so if a value appears at a, we
  • 8:41 - 8:44
    observe that and we immediately copy it onto
    b.
  • 8:44 - 8:47
    And if a value appears on b, then we
  • 8:47 - 8:51
    immediately copy it over into a. But I'm showing
  • 8:51 - 8:52
    this, the mechanics of it, so that you can
  • 8:52 - 8:55
    forget about them. Because you, when, when
    we're talking
  • 8:55 - 8:57
    about sound traveling, you don't really want
    to think
  • 8:57 - 9:00
    about the particles knocking together. What
    you really want
  • 9:00 - 9:02
    to think about is the data flowing through,
    just
  • 9:02 - 9:06
    like it's a pipe.
  • 9:06 - 9:08
    And this is good, because it, it, it decouples
  • 9:08 - 9:11
    that data flow from your computation, so you
    can
  • 9:11 - 9:14
    compose your different models together just
    by making them
  • 9:14 - 9:18
    overlap at well-known points. So to, to, to
    show
  • 9:18 - 9:20
    this in action, I've got a model here called
  • 9:20 - 9:23
    the desaturator. And on the left, it takes
    a
  • 9:23 - 9:26
    color and on the bottom, there's a, a, a
  • 9:26 - 9:30
    value, a real number between zero and one,
    and
  • 9:30 - 9:33
    then the color on the right is a desaturated
  • 9:33 - 9:36
    version of the color on the left.
  • 9:36 - 9:41
    So and, and that relationship is, it's, it's
    a,
  • 9:41 - 9:44
    it's, it's, it's pure. The, the value of that
  • 9:44 - 9:47
    color on the right, no matter what the color
  • 9:47 - 9:49
    on the left, is always going to be a
  • 9:49 - 9:52
    desaturated version of that color. So if we
    see
  • 9:52 - 9:55
    this, we can now plug it into our swatch
  • 9:55 - 10:00
    assembly, just using data binding. So, let's
    see that
  • 10:00 - 10:02
    in action.
  • 10:02 - 10:05
    Here's our desaturater. I've got the green
    turned on.
  • 10:05 - 10:08
    And as we up the desaturation, you can see
  • 10:08 - 10:10
    that it literally just sucks the color right
    out
  • 10:10 - 10:14
    until, if you're fully desaturated, you're
    at gray. If
  • 10:14 - 10:18
    you ever, never heard the term of desaturation
    before,
  • 10:18 - 10:20
    that's, that's, that's what it is.
  • 10:20 - 10:25
    And, of course, if I change it to a
  • 10:25 - 10:28
    different color, in this case black, which
    is the
  • 10:28 - 10:31
    absence of color, then they're, they're both
    black, because
  • 10:31 - 10:35
    a desaturated nothing is still nothing. But
    if I
  • 10:35 - 10:40
    shine the color through again, then the, the
    desaturation
  • 10:40 - 10:42
    remains.
  • 10:42 - 10:43
    And this is all well and good when it
  • 10:43 - 10:47
    comes to binding colors to colors. But when
    you've
  • 10:47 - 10:50
    got two separate data types, because remember,
    you know,
  • 10:50 - 10:52
    bindings can only work on the same data type.
  • 10:52 - 10:55
    When you've got two separate data types, what
    are
  • 10:55 - 10:58
    you gonna do? Well, you just need another
    model.
  • 10:58 - 11:04
    And in this case, what I've implemented here
    is
  • 11:04 - 11:06
    what I call a color syntax. And it's a
  • 11:06 - 11:09
    model that's got a color on one end and
  • 11:09 - 11:12
    a string on the other. And I'm, you know,
  • 11:12 - 11:14
    there's a little bit of hand-waving here,
    because this
  • 11:14 - 11:17
    model is a little bit complex on the inside,
  • 11:17 - 11:21
    but from a composability standpoint, it's
    very simple. It
  • 11:21 - 11:25
    just relates a color and a string.
  • 11:25 - 11:27
    And it goes both ways. So that if a
  • 11:27 - 11:30
    color appears on the top, that implies a string
  • 11:30 - 11:33
    value on the bottom. And if a new string
  • 11:33 - 11:36
    value appears on the bottom, that implies
    a different
  • 11:36 - 11:38
    color value on the top. And so I can
  • 11:38 - 11:41
    plug this in to our assembly, and I'm gonna
  • 11:41 - 11:43
    go ahead and plug it in twice, to kind
  • 11:43 - 11:45
    of fast forward and show you a little bit
  • 11:45 - 11:48
    more the power of data binding here.
  • 11:48 - 11:53
    So we've got two text inputs which produce
    strings.
  • 11:53 - 11:57
    But they're bound to our color syntaxes, but
    both
  • 11:57 - 11:59
    color syntaxes are bound to the same color,
    which
  • 11:59 - 12:02
    is that swatch on the right.
  • 12:02 - 12:03
    So we can see this in, in action here.
  • 12:03 - 12:06
    So I've got my two, two text fields, and
  • 12:06 - 12:08
    I can change the color of one, where probably
  • 12:08 - 12:11
    most, we're used to dealing with hex values,
    and
  • 12:11 - 12:14
    you can see that the, the colors update. Both
  • 12:14 - 12:17
    in the swatch, the, the desaturated value
    of the
  • 12:17 - 12:24
    swatch. And also in the other text field.
    So
  • 12:25 - 12:26
    I can set it to cyan and then I
  • 12:26 - 12:29
    get a desaturated cyan. Cause all I'm really
    doing
  • 12:29 - 12:32
    is changing that one color value.
  • 12:32 - 12:37
    Incidentally, these, these text fields, there's
    nothing special about
  • 12:37 - 12:39
    the format, because the way I implemented
    it is
  • 12:39 - 12:42
    a, a color syntax, I actually can take this
  • 12:42 - 12:49
    here and, and copy it up here, and it'll
  • 12:49 - 12:53
    still update the color because the, the syntax
    is
  • 12:53 - 12:56
    format agnostic. So it doesn't really matter.
    And I
  • 12:56 - 12:58
    can also use a RGB constructor here to make
  • 12:58 - 13:03
    this red again.
  • 13:03 - 13:08
    So. And that's good. You know, we can, we
  • 13:08 - 13:10
    can play around with the colors. We can enter
  • 13:10 - 13:14
    in RGB values here, one at a time, and
  • 13:14 - 13:15
    see the kind of the affect they have on
  • 13:15 - 13:18
    the mixed color. But that doesn't give us
    real
  • 13:18 - 13:21
    insight about the, the, the individual components.
    So what
  • 13:21 - 13:24
    we can do is we can actually add another
  • 13:24 - 13:27
    model to decompose this color into its RBG
    value.
  • 13:27 - 13:30
    So we've got, again, we're relating over here
    on
  • 13:30 - 13:33
    the left a color value, and over on the
  • 13:33 - 13:37
    right, three different, three different coordinates,
    red, green, and
  • 13:37 - 13:41
    blue. And we can see how those things relate
  • 13:41 - 13:45
    to each other just by binding it into, binding
  • 13:45 - 13:48
    it into our application.
  • 13:48 - 13:52
    Now I've gotten rid of the, the desaturator
    and
  • 13:52 - 13:55
    put this RGB selector in here. So let's see
  • 13:55 - 13:57
    what this ends up looking like. You can see
  • 13:57 - 14:02
    I've got these sliders bound to those RGB
    values,
  • 14:02 - 14:06
    and I can do things like bring in red
  • 14:06 - 14:08
    so that I've got, now, a pure yellow, and
  • 14:08 - 14:12
    I can fade out the green until I've got
  • 14:12 - 14:17
    my pure red. And so I can see how
  • 14:17 - 14:22
    each individual color affects the, the final
    value.
  • 14:22 - 14:24
    Which is, you know, this is, this is, this
  • 14:24 - 14:29
    is pretty neat. We're starting to, to get
    something
  • 14:29 - 14:34
    of a, of a more non-trivial application. But
    we
  • 14:34 - 14:38
    still, we're still not seeing how the color
    is
  • 14:38 - 14:41
    actually constructed by the computer. And
    to do that,
  • 14:41 - 14:44
    we can use, we can, we can visualize not
  • 14:44 - 14:47
    just the, the final output in that swatch,
    but
  • 14:47 - 14:52
    we can actually visualize each value for red,
    green,
  • 14:52 - 14:54
    and blue, and how that relates to the original
  • 14:54 - 14:56
    color.
  • 14:56 - 15:01
    So, what I did was I made an RGB
  • 15:01 - 15:04
    visualization component, and bound it to the
    color, so
  • 15:04 - 15:07
    that when the color updated, we visualize
    not the
  • 15:07 - 15:11
    whole color, like the swatch, but the actual
    different
  • 15:11 - 15:14
    red, green, and blue values. And that's what
    this
  • 15:14 - 15:17
    looks like. You can see we've got, right here
  • 15:17 - 15:23
    a pure green. But we can bring red in,
  • 15:23 - 15:25
    slowly. And you can see how you get that,
  • 15:25 - 15:28
    that yellow there, and then if we bring in
  • 15:28 - 15:31
    blue, how it goes to white. But what we're
  • 15:31 - 15:36
    seeing, now, is we're actually seeing how
    the color
  • 15:36 - 15:41
    is added by the, the, the actual hardware.
    RGC
  • 15:41 - 15:44
    is an additive model. We're taking a red value,
  • 15:44 - 15:46
    a green value, and a blue value and we're
  • 15:46 - 15:47
    adding them together so that the part where
    all
  • 15:47 - 15:52
    the circles overlap, that's all three colors
    added together.
  • 15:52 - 15:54
    And then where only two of the circles overlap,
  • 15:54 - 15:56
    those are where the other two circles are,
    are
  • 15:56 - 15:59
    together. So you can see that if I've got
  • 15:59 - 16:02
    a pure yellow or I've got a pure cyan.
  • 16:02 - 16:07
    Oops. If I've got a pure cyan, you know,
  • 16:07 - 16:10
    I have no, I have no red component, and
  • 16:10 - 16:13
    so the, the, the swatch or the part in
  • 16:13 - 16:15
    the middle is the exact same as the overlap
  • 16:15 - 16:17
    for green and blue. And so you can kind
  • 16:17 - 16:19
    of play around with this and see how the
  • 16:19 - 16:22
    individual colors mix and not be, not be distracted
  • 16:22 - 16:27
    by the, the, the overall sum.
  • 16:27 - 16:30
    And RGB is a great. RGB is great, if
  • 16:30 - 16:33
    you happen to be a pixel. It can be
  • 16:33 - 16:36
    difficult for us to understand RGB. The reason
    that
  • 16:36 - 16:39
    we use RGB coordinates is because it's very
    easy
  • 16:39 - 16:41
    for a monitor to take three values, add them
  • 16:41 - 16:43
    together, and like, that's the frequency of
    light that
  • 16:43 - 16:45
    I need to emit. But that's not how we,
  • 16:45 - 16:51
    as humans, actually perceive it. And so there
    are,
  • 16:51 - 16:53
    there are other coordinate systems that are
    more in
  • 16:53 - 16:56
    tune with the way that we perceive color,
    which
  • 16:56 - 16:59
    unfortunately we don't actually use. You know,
    RGB is
  • 16:59 - 17:03
    kind of like the assembly language of, of
    color.
  • 17:03 - 17:06
    It's what the machine understand.
  • 17:06 - 17:12
    So, probably the most, the other most popular
    format,
  • 17:12 - 17:15
    the most popular coordinate system for describing
    color is
  • 17:15 - 17:19
    called HSL. And it, it stands for hue, saturation,
  • 17:19 - 17:22
    and lightness. To read briefly what these,
    these mean
  • 17:22 - 17:24
    or what they're defined as.
  • 17:24 - 17:26
    So, hue is the degree to which a stimulus
  • 17:26 - 17:29
    can be described as similar to or different
    from
  • 17:29 - 17:31
    stimuli that are described as red, green,
    blue, and
  • 17:31 - 17:36
    yellow. Saturation. The colorfulness of a
    color relative to
  • 17:36 - 17:41
    its own brightness. Lightness. The subjective
    brightness, perception of
  • 17:41 - 17:45
    a color for humans along a lightness/darkness
    axis.
  • 17:45 - 17:49
    Now, if you're like me, that really, even
    though
  • 17:49 - 17:52
    it's aimed at me, it's completely and totally
    incomprehensible.
  • 17:52 - 17:57
    The, the, the vocabulary definitely is about
    humans and
  • 17:57 - 18:00
    human perception, but it's still a black box.
    It's
  • 18:00 - 18:03
    still completely opaque. But, what we can
    do is
  • 18:03 - 18:06
    we can add another model, and we can decompose
  • 18:06 - 18:08
    that to unpack those individual coordinates
    and see how
  • 18:08 - 18:14
    they effect our, the, effect the different
    color values.
  • 18:14 - 18:15
    So let's go ahead and plug that in. I've
  • 18:15 - 18:18
    got an HSL selector, just like I had the
  • 18:18 - 18:20
    RGB selector, and we can see the, the, the
  • 18:20 - 18:23
    hue, saturation, and lightness coordinates
    over there on the
  • 18:23 - 18:26
    left. So, right now we have a pure green.
  • 18:26 - 18:29
    I can take it down to a pure red.
  • 18:29 - 18:32
    We can move the h. We're gonna keep s
  • 18:32 - 18:33
    and l, and you can see as I go
  • 18:33 - 18:35
    to green, the red fades out til I've got
  • 18:35 - 18:37
    a pure green, and then the blue fades in
  • 18:37 - 18:40
    till we've got a pure cyan. Then the green
  • 18:40 - 18:43
    fades out so that we've got a pure blue,
  • 18:43 - 18:46
    and then red fades back in to purple, and
  • 18:46 - 18:48
    then blue fades back out to red.
  • 18:48 - 18:51
    I particularly, I love as I, as you watch
  • 18:51 - 18:55
    the hue, seeing where the RGB sliders are
    going.
  • 18:55 - 18:57
    So you can see that the hue is going
  • 18:57 - 19:01
    around that color circle. It's going around
    the color
  • 19:01 - 19:06
    circle. And then as you adjust the saturation,
    you
  • 19:06 - 19:10
    can see, OK. The red's coming down and the
  • 19:10 - 19:12
    green and the blue are coming up in unison,
  • 19:12 - 19:14
    and when I fully have zero saturation, then
    we're
  • 19:14 - 19:20
    at a gray. And if I bring the saturation
  • 19:20 - 19:22
    up, the, the green and blue go down in
  • 19:22 - 19:25
    unison, and we're back to that pure color,
    that
  • 19:25 - 19:26
    pure hue.
  • 19:26 - 19:31
    So I think that this gives a, a much
  • 19:31 - 19:37
    better view on, on these different coordinates.
    Same thing
  • 19:37 - 19:39
    with lightness. You can see as we go from
  • 19:39 - 19:41
    point five to one, it's almost like we're
    just
  • 19:41 - 19:45
    mixing in white unless you've got nothing
    but white,
  • 19:45 - 19:47
    and as we decrease the lightness, you can
    see
  • 19:47 - 19:50
    those, the green and the blue come down together.
  • 19:50 - 19:54
    And then as we go from point five lightness
  • 19:54 - 19:58
    to zero, we're just fading that hue to black.
  • 19:58 - 20:02
    And so I think, even though the terminology
    that
  • 20:02 - 20:05
    you might read on Wikipedia about what HSL
    is
  • 20:05 - 20:09
    is very opaque, it actually becomes pretty
    clear about
  • 20:09 - 20:11
    what it is when you, when you can play
  • 20:11 - 20:13
    with the individual coordinates and see how
    it relates
  • 20:13 - 20:20
    to both the color at large, the, the, and,
  • 20:20 - 20:22
    and also the, the additive color model that
    the
  • 20:22 - 20:26
    computer's using.
  • 20:26 - 20:28
    And we can also, and we can, we can
  • 20:28 - 20:34
    visualize the HSL by making another visualizer,
    just like
  • 20:34 - 20:36
    we did with RGB. And we can bind it
  • 20:36 - 20:38
    into our color model. I think we've got what,
  • 20:38 - 20:43
    one, two, three, four, five different things.
    Six different
  • 20:43 - 20:45
    things. Let's see. One, two, three, four,
    five, six,
  • 20:45 - 20:48
    seven different things bound to this color.
  • 20:48 - 20:52
    So, we've got quite a robot we're building
    here.
  • 20:52 - 20:54
    And so this is, this is actually HSL space,
  • 20:54 - 20:56
    and you might already be familiar with the
    color
  • 20:56 - 20:59
    selectors that use HSL. You can see that as
  • 20:59 - 21:04
    I adjust the hue here, I'm going around that
  • 21:04 - 21:09
    color wheel. And those, you can see where
    the
  • 21:09 - 21:13
    color wheel fits on those, along the points.
    And
  • 21:13 - 21:17
    the color that's selected is, is right down
    there.
  • 21:17 - 21:21
    This, so what we're seeing here is the hue
  • 21:21 - 21:23
    goes around in a circle. It's an actually
    a
  • 21:23 - 21:27
    radial component. So, which is why it's from,
    you
  • 21:27 - 21:33
    know, zero to three-sixty. And then the saturation,
    or
  • 21:33 - 21:36
    the intensity of the hue, is the radius of
  • 21:36 - 21:40
    that circle. And then if we look at the
  • 21:40 - 21:46
    lightness here, you can see that the lightness,
    we
  • 21:46 - 21:50
    fade up to white at the top and then
  • 21:50 - 21:53
    fade down to black. There, so as we adjust
  • 21:53 - 21:56
    the, the lightness, we can go, we go up
  • 21:56 - 21:59
    to white at the top and down to black
  • 21:59 - 22:03
    at the bottom.
  • 22:03 - 22:06
    So, that's, that's pretty neat. I think, I
    think
  • 22:06 - 22:13
    there's a lot of power in that. By taking,
  • 22:13 - 22:15
    you know, just, just, just by binding to a
  • 22:15 - 22:20
    single value. But values, values are actually
    not just
  • 22:20 - 22:23
    on the client. You can actually treat a server,
  • 22:23 - 22:25
    for example, as a simple model. And so here,
  • 22:25 - 22:28
    I'm, we're going to have a server component.
    And
  • 22:28 - 22:31
    a server's a black box, but from the perspective
  • 22:31 - 22:33
    of the rest of the client, it behaves just
  • 22:33 - 22:34
    like any other model.
  • 22:34 - 22:38
    If a color appears at that point, it's sent
  • 22:38 - 22:40
    into the black box. It can be sent to
  • 22:40 - 22:44
    the server, serialized, whatever. And by the
    same token,
  • 22:44 - 22:45
    something can happen on the server and it
    can
  • 22:45 - 22:52
    make a color value appear right there.
  • 22:52 - 22:56
    So, we can use this concept to develop color
  • 22:56 - 22:58
    book, which is the first social network for
    color
  • 22:58 - 23:00
    values, which I'm about to show you. And we
  • 23:00 - 23:04
    can do this just by plugging in our server
  • 23:04 - 23:06
    into our robot. I was actually kind of running
  • 23:06 - 23:10
    out of room, so same basic concept. It's a
  • 23:10 - 23:13
    little bit of a snakey cable there.
  • 23:13 - 23:15
    And so now we'll do an actual live demo
  • 23:15 - 23:20
    in here. So I've got, I wrote a little
  • 23:20 - 23:27
    Rails app that uses web sockets to implement
    those
  • 23:27 - 23:31
    servers. Or implement that, the, the, the
    endpoints on
  • 23:31 - 23:37
    the servers. So, we can now open up that
  • 23:37 - 23:44
    example that you saw in two separate tabs.
  • 23:46 - 23:49
    And then we can see them acting in unison
  • 23:49 - 23:54
    here. And so what's actually happening here
    is I
  • 23:54 - 24:01
    got two different client-side applications,
    but they're all bound
  • 24:02 - 24:09
    together.
  • 24:13 - 24:20
    So, one of the things I hope to demonstrate
  • 24:27 - 24:31
    is that there is actual power in simplicity,
    with
  • 24:31 - 24:34
    keeping your models simple and keeping them
    composable. I
  • 24:34 - 24:36
    think that, you know, this is probably, in
    terms
  • 24:36 - 24:40
    of API, this was probably the, the most complex
  • 24:40 - 24:42
    model that we had in the system. It's got,
  • 24:42 - 24:44
    you know, four points that you can, you can
  • 24:44 - 24:49
    bind to.
  • 24:49 - 24:54
    But because, you know, because we understand
    the relationship
  • 24:54 - 24:57
    between them, we can use each one of these
  • 24:57 - 25:01
    individual models, which are very, very simple,
    to link
  • 25:01 - 25:05
    together in simple ways to make a very complex
  • 25:05 - 25:09
    and, and interesting application. And so I
    shied away
  • 25:09 - 25:12
    from, from actually defining a model, because
    like I
  • 25:12 - 25:14
    said, I don't want to get into nomenclature
    wars.
  • 25:14 - 25:17
    But I think it's fair to define a model
  • 25:17 - 25:21
    as just a group of values with well understood
  • 25:21 - 25:25
    relationships. Values with well understood
    relationships.
  • 25:25 - 25:28
    And if we understand those relationships than
    we can
  • 25:28 - 25:33
    compose them in very simple and easy ways.
    But
  • 25:33 - 25:37
    it's actually understanding the relationships
    that's the hard part.
  • 25:37 - 25:40
    The is where the, the bulk of the work
  • 25:40 - 25:43
    is.
  • 25:43 - 25:45
    And I think that, that Plato got that, you
  • 25:45 - 25:48
    know, when he original made this allegory
    of the
  • 25:48 - 25:53
    cave, one of his goals was to explain to
  • 25:53 - 25:58
    people what exactly a philosopher does. What
    his job
  • 25:58 - 26:01
    is. The philosopher's job is to look at those
  • 26:01 - 26:03
    pictures, which is the only thing that we
    can
  • 26:03 - 26:08
    conceive, and from it, infer and construct
    that model
  • 26:08 - 26:12
    or form that's standing in front of the fire.
  • 26:12 - 26:14
    And so when it comes to UI and, and
  • 26:14 - 26:20
    software in general, the philosophy part falls
    to you.
  • 26:20 - 26:24
    That's your job. It can be very satisfying
    and,
  • 26:24 - 26:26
    and rewarding and I hope you have fun with
  • 26:26 - 26:28
    it.
  • 26:28 - 26:29
    Thank you.
Title:
RailsConf 2014 - The Power of M by Charles Lowell
Description:

more » « less
Duration:
26:56

English subtitles

Revisions