Skip to content

Commit

Permalink
update for bacon.js 2.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
raimohanska committed Jan 28, 2018
1 parent e5216b5 commit fa5b219
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 29 deletions.
29 changes: 22 additions & 7 deletions dist/baret.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ var eventValue = bacon2 ? function (e) {
} : function (e) {
return e.value();
};
var hasValue = bacon2 ? function (e) {
return e.hasValue;
} : function (e) {
return e.hasValue();
};
var isError = bacon2 ? function (e) {
return e.isError;
} : function (e) {
return e.isError();
};
var isEnd = bacon2 ? function (e) {
return e.isEnd;
} : function (e) {
return e.isEnd();
};
//

var LiftedComponent = /*#__PURE__*/infestines.inherit(function LiftedComponent(props) {
Expand Down Expand Up @@ -61,12 +76,12 @@ var FromBacon = /*#__PURE__*/infestines.inherit(function FromBacon(props) {

if (isObs(observable)) {
var callback = function callback(e) {
if (e.hasValue()) {
if (hasValue(e)) {
_this.rendered = eventValue(e) || null;
_this.forceUpdate();
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else if (e.isEnd()) {
} else if (isEnd(e)) {
_this.unsub = null;
}
};
Expand Down Expand Up @@ -201,14 +216,14 @@ function onAny(self, obs) {
while (handlers[idx] !== handler) {
++idx;
} // Found the index of this handler/value
if (e.hasValue()) {
if (hasValue(e)) {
var value = eventValue(e);
var values = self.values;
if (values[idx] !== value) {
values[idx] = value;
self.forceUpdate();
}
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else {
// This is End
Expand Down Expand Up @@ -258,13 +273,13 @@ var FromClass = /*#__PURE__*/infestines.inherit(function FromClass(props) {
{
this.values = this;
var handlers = function handlers(e) {
if (e.hasValue()) {
if (hasValue(e)) {
var value = eventValue(e);
if (_this2.values !== value) {
_this2.values = value;
_this2.forceUpdate();
}
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else {
// Assume this is End
Expand Down
29 changes: 22 additions & 7 deletions dist/baret.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ var eventValue = bacon2 ? function (e) {
} : function (e) {
return e.value();
};
var hasValue = bacon2 ? function (e) {
return e.hasValue;
} : function (e) {
return e.hasValue();
};
var isError = bacon2 ? function (e) {
return e.isError;
} : function (e) {
return e.isError();
};
var isEnd = bacon2 ? function (e) {
return e.isEnd;
} : function (e) {
return e.isEnd();
};
//

var LiftedComponent = /*#__PURE__*/inherit(function LiftedComponent(props) {
Expand Down Expand Up @@ -54,12 +69,12 @@ var FromBacon = /*#__PURE__*/inherit(function FromBacon(props) {

if (isObs(observable)) {
var callback = function callback(e) {
if (e.hasValue()) {
if (hasValue(e)) {
_this.rendered = eventValue(e) || null;
_this.forceUpdate();
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else if (e.isEnd()) {
} else if (isEnd(e)) {
_this.unsub = null;
}
};
Expand Down Expand Up @@ -194,14 +209,14 @@ function onAny(self, obs) {
while (handlers[idx] !== handler) {
++idx;
} // Found the index of this handler/value
if (e.hasValue()) {
if (hasValue(e)) {
var value = eventValue(e);
var values = self.values;
if (values[idx] !== value) {
values[idx] = value;
self.forceUpdate();
}
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else {
// This is End
Expand Down Expand Up @@ -251,13 +266,13 @@ var FromClass = /*#__PURE__*/inherit(function FromClass(props) {
{
this.values = this;
var handlers = function handlers(e) {
if (e.hasValue()) {
if (hasValue(e)) {
var value = eventValue(e);
if (_this2.values !== value) {
_this2.values = value;
_this2.forceUpdate();
}
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else {
// Assume this is End
Expand Down
29 changes: 22 additions & 7 deletions dist/baret.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ var eventValue = bacon2 ? function (e) {
} : function (e) {
return e.value();
};
var hasValue = bacon2 ? function (e) {
return e.hasValue;
} : function (e) {
return e.hasValue();
};
var isError = bacon2 ? function (e) {
return e.isError;
} : function (e) {
return e.isError();
};
var isEnd = bacon2 ? function (e) {
return e.isEnd;
} : function (e) {
return e.isEnd();
};
//

var LiftedComponent = /*#__PURE__*/infestines.inherit(function LiftedComponent(props) {
Expand Down Expand Up @@ -59,12 +74,12 @@ var FromBacon = /*#__PURE__*/infestines.inherit(function FromBacon(props) {

if (isObs(observable)) {
var callback = function callback(e) {
if (e.hasValue()) {
if (hasValue(e)) {
_this.rendered = eventValue(e) || null;
_this.forceUpdate();
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else if (e.isEnd()) {
} else if (isEnd(e)) {
_this.unsub = null;
}
};
Expand Down Expand Up @@ -199,14 +214,14 @@ function onAny(self, obs) {
while (handlers[idx] !== handler) {
++idx;
} // Found the index of this handler/value
if (e.hasValue()) {
if (hasValue(e)) {
var value = eventValue(e);
var values = self.values;
if (values[idx] !== value) {
values[idx] = value;
self.forceUpdate();
}
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else {
// This is End
Expand Down Expand Up @@ -256,13 +271,13 @@ var FromClass = /*#__PURE__*/infestines.inherit(function FromClass(props) {
{
this.values = this;
var handlers = function handlers(e) {
if (e.hasValue()) {
if (hasValue(e)) {
var value = eventValue(e);
if (_this2.values !== value) {
_this2.values = value;
_this2.forceUpdate();
}
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error;
} else {
// Assume this is End
Expand Down
2 changes: 1 addition & 1 deletion dist/baret.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions src/baret.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const Component = React.Component
const isObs = x => x instanceof Observable
const bacon2 = typeof (Bacon.Next().value) != "function"
const eventValue = bacon2 ? e => e.value : e => e.value()
const hasValue = bacon2 ? e => e.hasValue : e => e.hasValue()
const isError = bacon2 ? e => e.isError : e => e.isError()
const isEnd = bacon2 ? e => e.isEnd : e => e.isEnd()
//

const LiftedComponent = /*#__PURE__*/inherit(function LiftedComponent(props) {
Expand Down Expand Up @@ -53,12 +56,12 @@ const FromBacon = /*#__PURE__*/inherit(function FromBacon(props) {
doSubscribe({observable}) {
if (isObs(observable)) {
const callback = e => {
if (e.hasValue()) {
if (hasValue(e)) {
this.rendered = eventValue(e) || null
this.forceUpdate()
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error
} else if (e.isEnd()) {
} else if (isEnd(e)) {
this.unsub = null
}
}
Expand Down Expand Up @@ -200,14 +203,14 @@ function onAny(self, obs) {
while (handlers[idx] !== handler)
++idx
// Found the index of this handler/value
if (e.hasValue()) {
if (hasValue(e)) {
const value = eventValue(e)
const values = self.values
if (values[idx] !== value) {
values[idx] = value
self.forceUpdate()
}
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error
} else { // This is End
handlers[idx] = null
Expand Down Expand Up @@ -255,13 +258,13 @@ const FromClass = /*#__PURE__*/inherit(function FromClass(props) {
case 1: {
this.values = this
const handlers = e => {
if (e.hasValue()) {
if (hasValue(e)) {
const value = eventValue(e)
if (this.values !== value) {
this.values = value
this.forceUpdate()
}
} else if (e.isError()) {
} else if (isError(e)) {
throw e.error
} else { // Assume this is End
this.values = [this.values]
Expand Down

0 comments on commit fa5b219

Please sign in to comment.