-
Notifications
You must be signed in to change notification settings - Fork 481
Make the example more concrete #534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,11 +30,16 @@ you have a lightbulb in a room in a house. The lightbulb is currently turned | |
on, and it's controlled by two three-way switches and a clapper: | ||
|
||
``` | ||
<style> | ||
.on { background-color: yellow; } | ||
.off { background-color: black; color: white; } | ||
</style> | ||
|
||
<div class="room" id="kitchen"> | ||
<div class="lightbulb on"></div> | ||
<div class="switch"></div> | ||
<div class="switch"></div> | ||
<div class="clapper"></div> | ||
<div class="lightbulb on">My room light</div> | ||
<div class="switch">Switch 1</div> | ||
<div class="switch">Switch 2</div> | ||
<div class="clapper">Clapper switch</div> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR sorta overlaps with #535. Let's take care of it there. |
||
</div> | ||
``` | ||
|
||
|
@@ -55,10 +60,10 @@ $( ".switch, .clapper" ).click(function() { | |
}); | ||
``` | ||
|
||
With custom events, your code might look more like this: | ||
With custom events, we can define our own events. Then your code might look more like this: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer we reword this a bit more and also stuck with the shorter
|
||
|
||
``` | ||
$( ".lightbulb" ).on( "changeState", function( e ) { | ||
$( ".lightbulb" ).on( "changeTheLightState", function( e ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a better name now, committed in f9d0ab3. |
||
var light = $( this ); | ||
if ( light.hasClass( "on" ) ) { | ||
light.removeClass( "on" ).addClass( "off" ); | ||
|
@@ -68,11 +73,11 @@ $( ".lightbulb" ).on( "changeState", function( e ) { | |
}); | ||
|
||
$( ".switch, .clapper" ).click(function() { | ||
$( this ).parent().find( ".lightbulb" ).trigger( "changeState" ); | ||
$( this ).parent().find( ".lightbulb" ).trigger( "changeTheLightState" ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a better name now, committed in f9d0ab3. |
||
}); | ||
``` | ||
|
||
This last bit of code is not that exciting, but something important has happened: we've moved the behavior of the lightbulb away from the switches and the clapper and to the lightbulb itself. | ||
Here something important has happened: we've moved the behavior of the lightbulb away from the switches and the clapper and to the lightbulb itself. | ||
|
||
Let's make our example a little more interesting. We'll add another room to our house, along with a master switch, as shown here: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let us handle this together with #535.