-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.html
216 lines (171 loc) · 7.65 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<!-- This file is generated. See package.json -->
<html>
<head>
<title>Bacon.js - Functional Reactive Programming library for JavaScript</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta name="keywords" content="bacon.js, FPR, functional reactive programming, javascript, reactive programming" />
<meta name="description" content="Bacon.js is a functional reactive programming library for javascript." />
<link rel="stylesheet" type="text/css" href="normalize.css" >
<link rel="stylesheet" type="text/css" href="foundation.min.css" >
<link rel="stylesheet" type="text/css" href="codemirror/codemirror.css" >
<link rel="stylesheet" type="text/css" href="marble.css">
<link rel="stylesheet" type="text/css" href="bacon.css" >
<link href='//fonts.googleapis.com/css?family=Yanone+Kaffeesatz' rel='stylesheet' type='text/css'>
<script src="//codeorigin.jquery.com/jquery-2.1.1.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bacon.js/3.0.17/Bacon.min.js"></script>
<script>
Bacon.$.init($)
</script>
<script src="codemirror/codemirror.js"></script>
<script src="codemirror/javascript.js"></script>
<script src="marble.js"></script>
<script src="example.js"></script>
</script>
</head>
<body>
<div class="grid row">
<div class="large-4 columns sidebar">
<div class="logo">
<a href="index.html"><img alt="bacon.js logo" src="logo.png" /></a>
</div>
<div class="download">
<a class="button big-button" href="http://cdnjs.cloudflare.com/ajax/libs/bacon.js/3.0.17/Bacon.js" download>
Download Bacon.js
<small>v3.0.17</small>
<a class="github" href="https://github.com/baconjs/bacon.js#install-and-usage">[More install options]</a>
</a>
</div>
<div class="menu">
<div class="row">
<div class="large-12 small-6 columns">
<p> <a href="api.html"> API docs <small>(1.0)</small> </a> </p>
<p> <a href="api2.html"> API docs <small>(2.0)</small> </a> </p>
<p> <a href="api3/index.html"> API docs <small>(3.0)</small> </a> </p>
<p> <a href="tutorials.html"> Tutorials </a> </p>
<p> <a href="https://github.com/baconjs/bacon.js#install">Install/Download</a> </p>
</div>
<div class="large-12 small-6 columns">
<p> <a href="https://github.com/baconjs/bacon.js/wiki/FAQ">FAQ</a> </p>
</div>
<div class="large-12 small-6 columns">
<p><a href="https://reaktor.com/"><img src="supported-by-reaktor.png" class="sponsor reaktor"></a></p>
</div>
</div>
</div>
</div>
<div class="large-8 columns">
<div class="main">
<h1> What is Bacon.js? </h1>
<p>
A small functional reactive programming lib for JavaScript.
Turns your event spaghetti into clean and declarative feng
shui bacon, by switching from imperative to functional. It's
like replacing nested for-loops with functional programming
concepts like <a href="api3/classes/observable.html#map"><code>map</code></a> and <a href="api3/classes/observable.html#filter"><code>filter</code></a>. Stop
working on individual events and work with event-streams
instead. Transform your data with <a href="api3/classes/observable.html#map"><code>map</code></a> and <a href="api3/classes/observable.html#filter"><code>filter</code></a>.
Combine your data with <a href="api3/globals.html#mergeall"><code>merge</code></a> and
<a href="api3/globals.html#combinewith"><code>combine</code></a>. Then switch to the heavier weapons and
wield <a href="api3/classes/observable.html#flatmap"><code>flatMap</code></a> and <a href="api3/globals.html#combinetemplate"><code>combineTemplate</code></a>
like a boss.
It's the <code>_</code> of Events. Too bad the
symbol <code>~</code> is not allowed in Javascript.
</p>
<h1> Getting started </h1>
<p>
Check out the <a href="http://raimohanska.github.io/bacon.js-slides/index.html">introduction (slideshow)</a>,
the <a href="/api.html">API reference</a> and the
<a href="https://github.com/baconjs/bacon.js">GitHub page</a>. Or take
a look at one of the tutorials to learn how to use Bacon.js on the
<a href="http://blog.flowdock.com/2013/01/22/functional-reactive-programming-with-bacon-js/">client</a>,
<a href="http://abesto.net/bacon-js-on-the-server/">server</a> or in
<a href="http://philipnilsson.github.io/badness/">game programming</a>.
</p>
<h1> Examples </h1>
<h3> Simple counter </h3>
<div class="example">
<div class="example-html">
<p> <i> Behold!</i> It counts up and down as you click the buttons </p>
<button id="up"> Up </button>
<button id="down"> Down </button>
<span id="counter"> 0 </span>
</div>
<textarea>var up = Bacon.fromEvent($('#up'), 'click');
var down = Bacon.fromEvent($('#down'), 'click');
var counter =
// map up to 1, down to -1
up.map(1).merge(down.map(-1))
// accumulate sum
.scan(0, (x,y) => x + y);
// assign observable value to jQuery property text
counter.onValue(text => $('#counter').text(text));</textarea>
<button class="run">Reload</button>
</div>
<h3> Movie Search </h3>
<div class="example">
Type a word with at least three characters into the box.
<script>
function queryMovie(query) {
return jQuery.get(
'//api.themoviedb.org/3/search/movie?api_key=9eae05e667b4d5d9fbb75d27622347fe&query=' + query
).then(r => r.results);
}
function showMovie(result) {
var link = $('<a/>')
.attr('href', 'https://www.themoviedb.org/movie/' + result.id)
.text(result.title);
return $('<div/>').append(link).css('padding', '0.1em 0');
}
</script>
<div class="example-html" style="padding: 1em 0">
<input type="text" id="input"/>
<div id="results" style="position: absolute; display: block; z-index:1000; background-color: white; padding: 0.5em"></div>
</div>
<textarea>function movieSearch(query) {
if (query.length < 3)
// show no results for queries of length < 3
return Bacon.once([]);
return Bacon.fromPromise(queryMovie(query));
}
var text = Bacon.fromEvent($('#input'), 'keydown')
// limit the rate of queries
.debounce(300)
// get input text value from each event
.map(event => event.target.value)
// Ignore duplicate events with same text
.skipDuplicates();
// React to text changes by doing a lookup with
// api function movieSearch, creating a new observable
// with the results.
//
// Make sure to always react to the latest, value even
// if responses from the server arrives out of order
var suggestions =
text.flatMapLatest(movieSearch);
// Display "Searching..." when waiting for the results
text.awaiting(suggestions).onValue(x => {
if (x) $('#results').html('Searching...');
});
// Render suggestion results to DOM
suggestions.onValue(results => {
$('#results').html($.map(results, showMovie));
});</textarea>
<button class="run">Reload</button>
</div>
<br>
<i>Next, you might want to check out our <a href="tutorials.html">Tutorials</a>.</i>
</div>
</div>
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-58079902-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>