Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: java
sudo: false

jdk:
- openjdk7
- oraclejdk8

cache:
Expand Down
6 changes: 6 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Michael Bayne <mdb@samskivert.com>
Charlie Groves <charlie.groves@gmail.com>
Tim Conkling <tconkling@gmail.com>
David Hoover <karma@deadmoose.com>
Bruno Garcia <b@aduros.com>
Ray J. Greenwell <ray@threerings.net>
2 changes: 1 addition & 1 deletion etc/SOURCE_HEADER
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// React - a library for functional-reactive-like programming
// Copyright (c) 2015, Three Rings Design, Inc. - All rights reserved.
// Copyright (c) 2011-present, React Authors
// http://github.com/threerings/react/blob/master/LICENSE

4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<groupId>com.threerings</groupId>
<artifactId>react</artifactId>
<packaging>jar</packaging>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>

<name>react</name>
<description>A signals/slots plus FRP-like library for Java.</description>
Expand Down Expand Up @@ -47,7 +47,7 @@
</prerequisites>

<properties>
<source.level>1.7</source.level>
<source.level>1.8</source.level>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down
138 changes: 69 additions & 69 deletions src/main/java/react/AbstractSignal.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// React - a library for functional-reactive-like programming in Java
// Copyright (c) 2011, Three Rings Design, Inc. - All rights reserved.
// React - a library for functional-reactive-like programming
// Copyright (c) 2011-present, React Authors
// http://github.com/threerings/react/blob/master/LICENSE

package react;
Expand All @@ -10,81 +10,81 @@
* exposing a public interface for emitting events. This can be used by entities which wish to
* expose a signal-like interface for listening, without allowing external callers to emit signals.
*/
public class AbstractSignal<T> extends Reactor implements SignalView<T>
{
@Override public <M> SignalView<M> map (final Function<? super T, M> func) {
final AbstractSignal<T> outer = this;
return new MappedSignal<M>() {
@Override protected Connection connect () {
return outer.connect(new Listener<T>() {
@Override public void onEmit (T value) {
notifyEmit(func.apply(value));
}
});
}
};
}
public class AbstractSignal<T> extends Reactor implements SignalView<T> {

@Override public <M> SignalView<M> map (final Function<? super T, M> func) {
final AbstractSignal<T> outer = this;
return new MappedSignal<M>() {
@Override protected Connection connect () {
return outer.connect(new Listener<T>() {
@Override public void onEmit (T value) {
notifyEmit(func.apply(value));
}
});
}
};
}

@Override public SignalView<T> filter (final Function<? super T, Boolean> pred) {
final AbstractSignal<T> outer = this;
return new MappedSignal<T>() {
@Override protected Connection connect () {
return outer.connect(new Listener<T>() {
@Override public void onEmit (T value) {
if (pred.apply(value)) {
notifyEmit(value);
}
}
});
@Override public SignalView<T> filter (final Function<? super T, Boolean> pred) {
final AbstractSignal<T> outer = this;
return new MappedSignal<T>() {
@Override protected Connection connect () {
return outer.connect(new Listener<T>() {
@Override public void onEmit (T value) {
if (pred.apply(value)) {
notifyEmit(value);
}
};
}
}
});
}
};
}

@Override public <M> SignalView<M> collect (final Function<? super T, M> collector) {
final AbstractSignal<T> outer = this;
return new MappedSignal<M>() {
@Override protected Connection connect () {
return outer.connect(new Listener<T>() {
@Override public void onEmit (T value) {
M mapped = collector.apply(value);
if (mapped != null) {
notifyEmit(mapped);
}
}
});
@Override public <M> SignalView<M> collect (final Function<? super T, M> collector) {
final AbstractSignal<T> outer = this;
return new MappedSignal<M>() {
@Override protected Connection connect () {
return outer.connect(new Listener<T>() {
@Override public void onEmit (T value) {
M mapped = collector.apply(value);
if (mapped != null) {
notifyEmit(mapped);
}
};
}
}
});
}
};
}

@Override public RFuture<T> next () {
final RPromise<T> result = RPromise.create();
connect(result.succeeder()).once();
return result;
}
@Override public RFuture<T> next () {
final RPromise<T> result = RPromise.create();
connect(result::succeed).once();
return result;
}

@Override public Connection connect (Listener<? super T> slot) {
return addConnection(slot);
}
@Override public Connection connect (Listener<? super T> slot) {
return addConnection(slot);
}

@Override public void disconnect (Listener<? super T> slot) {
removeConnection(slot);
}
@Override public void disconnect (Listener<? super T> slot) {
removeConnection(slot);
}

@Override Listener<T> placeholderListener () {
@SuppressWarnings("unchecked") Listener<T> p = (Listener<T>)Slots.NOOP;
return p;
}
@Override Listener<T> placeholderListener () {
@SuppressWarnings("unchecked") Listener<T> p = (Listener<T>)Slot.NOOP;
return p;
}

/**
* Emits the supplied event to all connected slots.
*/
protected void notifyEmit (T event) {
notify(EMIT, event, null, null);
}
/**
* Emits the supplied event to all connected slots.
*/
protected void notifyEmit (T event) {
notify(EMIT, event, null, null);
}

@SuppressWarnings("unchecked") protected static final Notifier EMIT = new Notifier() {
public void notify (Object slot, Object event, Object _1, Object _2) {
((Listener<Object>)slot).onEmit(event);
}
};
@SuppressWarnings("unchecked") protected static final Notifier EMIT = new Notifier() {
public void notify (Object slot, Object event, Object _1, Object _2) {
((Listener<Object>)slot).onEmit(event);
}
};
}
Loading