Skip to content

Commit c37a27f

Browse files
committed
rewrite in livescript
1 parent 78fd796 commit c37a27f

File tree

11 files changed

+104
-296
lines changed

11 files changed

+104
-296
lines changed

.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
/dist
1+
/src
2+
/spec
3+
/gulpfile.ls

dist/maps/resolver.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-bacon.js

Lines changed: 0 additions & 106 deletions
This file was deleted.

dist/resolver.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gruntfile.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

gulpfile.ls

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
gulp = require 'gulp'
2+
gutil = require 'gulp-util'
3+
livescript = require 'gulp-livescript'
4+
sourcemaps = require 'gulp-sourcemaps'
5+
6+
gulp.task 'default', ->
7+
gulp.src './src/*.ls'
8+
.pipe sourcemaps.init()
9+
.pipe livescript bare: true .on('error', gutil.log)
10+
.pipe sourcemaps.write('./maps')
11+
.pipe gulp.dest('./dist')

package.json

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
{
22
"name": "react-bacon",
3-
"version": "0.0.4",
4-
"description": "A little module for using React with Bacon.js",
5-
"main": "src/react-bacon.js",
3+
"version": "0.1.0",
4+
"description": "Incorporate BaconJS into the ReactJS render cycle",
5+
"main": "dist/index.js",
6+
"author": "Rodolfo Hansen",
7+
"homepage": "https://github.com/kryptt/react-bacon",
8+
"license": "MIT",
9+
"keywords": [
10+
"async",
11+
"react",
12+
"bacon",
13+
"reactive",
14+
"streams",
15+
"isomorphic"
16+
],
617
"repository": {
718
"type": "git",
8-
"url": "https://github.com/jamesmacaulay/react-bacon"
19+
"url": "https://github.com/kryptt/react-bacon"
920
},
10-
"author": "James MacAulay",
11-
"license": "MIT",
1221
"bugs": {
13-
"url": "https://github.com/jamesmacaulay/react-bacon/issues"
22+
"url": "https://github.com/kryptt/react-bacon/issues"
23+
},
24+
"scripts": {
25+
"build": "gulp"
1426
},
15-
"homepage": "https://github.com/jamesmacaulay/react-bacon",
1627
"devDependencies": {
17-
"react": "~0.10.0",
18-
"grunt": "~0.4.4",
19-
"grunt-contrib-jasmine": "~0.6.3",
20-
"browserify": "~3.44.2",
21-
"grunt-browserify": "~2.0.8",
22-
"reactify": "~0.13.1",
23-
"browserify-shim": "~3.4.1"
28+
"gulp": "^3.9.0",
29+
"gulp-livescript": "^2.4.0",
30+
"gulp-sourcemaps": "^1.5.2",
31+
"gulp-util": "^3.0.6",
32+
"livescript": "^1.4.0"
2433
},
2534
"dependencies": {
26-
"baconjs": "~0.7.10"
35+
"baconjs": "^0.7.70"
2736
},
28-
"browserify-shim": {
29-
"baconjs": "global:Bacon"
37+
"peerDependencies": {
38+
"react": "~0.13"
3039
}
3140
}

src/index.ls

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mixin = require './mixin'
2+
resolver = require './resolver'
3+
4+
module.exports =
5+
BaconMixin : mixin
6+
BaconResolver : resolver
7+
Mixin : mixin
8+
Resolver : resolver

src/mixin.ls

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
Bacon = require 'baconjs'
2+
3+
ensure-unsub = ->
4+
it._bacon ?= {}
5+
it._bacon.unsub ?= []
6+
ensure-buses = ->
7+
it._bacon ?= {}
8+
it._bacon.buses ?= {}
9+
ensure-props = ->
10+
ensure-buses it .props ?= new Bacon.Bus!
11+
ensure-state = ->
12+
ensure-buses it .state ?= new Bacon.Bus!
13+
14+
event-obj = -> "#{it.target.name}": it.target.value
15+
event-bus = (it, name, generator) ->
16+
bus = ensure-buses it .["event_#name"] ?= new Bacon.Bus!
17+
if it[name] then throw "Cannot re-implement the event-bus end-point"
18+
it[name] = generator(bus)
19+
bus
20+
21+
module.exports =
22+
# offer a bacon event stream for the component's properties.
23+
stream-props : (pn) -> if pn? then ensure-props @ else ensure-props @ .map -> it[pn]
24+
# offer a bacon event stream for the component's state.
25+
stream-state : (sn) -> if sn? then ensure-state @ else ensure-state @ .map -> it[sn]
26+
# register a callback hook and offer a stream on the other end of it.
27+
event-stream : (en) -> event-bus @, en, (bus) -> !-> bus.push it
28+
# similar to event-stream except we push it.target.value through the stream.
29+
value-stream : (en) -> event-bus @, en, (bus) -> !-> bus.push it.target.value
30+
# similar to event-stream except we push {it.target.name : it.target.value} through.
31+
input-stream : (en) -> event-bus @, en, (bus) -> !-> bus.push (it |> event-obj)
32+
# links the unsub function to the component's lifecycle.
33+
# unsub will be run in component-will-unmount.
34+
subscribe-to : (unsub) -> ensure-unsub @ .push unsub; unsub
35+
# plugs a stream into the components state.
36+
# either under a specific key, or overriding the entire state object.
37+
plug : (stream, key) -> @subscribe-to stream.on-value do
38+
if key? then !~> @set-state "#key": it else !~> @set-state it
39+
# push values to the props and state streams if they exist.
40+
component-did-update : !->
41+
if @_bacon?buses?
42+
@_bacon.buses.props?push @props
43+
@_bacon.buses.state?push @state
44+
# cleanup whenever the component unmounts.
45+
component-will-unmount : !->
46+
if @_bacon?
47+
if @_bacon.buses?
48+
for b of @_bacon.buses
49+
@_bacon.buses[b].end!
50+
@_bacon.unsub?for-each !-> it!
51+
@_bacon = {}

0 commit comments

Comments
 (0)