Skip to content

Commit 792d21d

Browse files
committed
remove rx and most from depends on typeclasses
1 parent 5ca3db1 commit 792d21d

File tree

8 files changed

+23
-346
lines changed

8 files changed

+23
-346
lines changed

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ test: unit integrate
88
build: lib/**/*.js
99

1010
lib/**/*.js: src/**/*.ts
11+
tsc
1112

1213
lib/%.js: src/%.ts
1314
tsc
1415

15-
all: test browser
16+
all: test dist
1617

17-
.PHONY: test build unit integrate browser docs docs/publish
18+
.PHONY: test build unit integrate dist docs docs/publish
1819

1920
unit: build
2021
yarn test
@@ -28,7 +29,7 @@ docs/src/main/tut/examples/example.js: docs/src/main/tut/examples/example.tsx
2829
watch/example: docs/src/main/tut/examples/example.tsx
2930
$(watchify) -p [tsify -p tsconfig.examples.json] -t envify docs/src/main/tut/examples/example.tsx -dv -o docs/src/main/tut/examples/example.js
3031

31-
browser: dist/xreact.min.js dist/xreact-most.min.js dist/xreact-rx.min.js
32+
dist: dist/xreact.min.js dist/xreact-most.min.js dist/xreact-rx.min.js
3233

3334
dist/xreact.js: lib/index.js dist/xreact-most.js dist/xreact-rx.js
3435
env NODE_ENV=production $(browserify) -t browserify-shim -t envify -x ./lib/xs $< -s xreact -o $@

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
},
2222
"browserify-shim": {
2323
"react": "global:React",
24+
"reflect-metadata": "global:Reflect",
2425
"@reactivex/rxjs": "global:Rx",
2526
"most": "global:most"
2627
},

src/fantasy/fantasyx.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ export class FantasyX<F extends Stream, I, S, A> {
3030
}
3131

3232
toStream(intent$: Subject<F, I>): $<F, Update<S>> {
33-
return map<Stream, State<S, A>, Update<S>>(
33+
return streamOps.map<State<S, A>, Update<S>>(
3434
s => (state => s.patch(a => a).runS(state)),
3535
this.plan.runA(intent$))
3636
}
3737

3838
map<B>(f: (a: A) => B): FantasyX<F, I, S, B> {
3939
return new FantasyX<F, I, S, B>(
4040
Functor.State.map(update$ => (
41-
map<Stream, State<S, A>, State<S, B>>(state => (
41+
streamOps.map<State<S, A>, State<S, B>>(state => (
4242
Functor.State.map(f, state)
4343
), update$)
4444
), this.plan)
@@ -48,7 +48,7 @@ export class FantasyX<F extends Stream, I, S, A> {
4848
foldS<B>(f: (s: S, a: A) => S): FantasyX<F, I, S, Partial<S>> {
4949
return new FantasyX<F, I, S, Partial<S>>(
5050
Functor.State.map(update$ => (
51-
map<Stream, State<S, A>, State<S, Partial<S>>>(state => (
51+
streamOps.map<State<S, A>, State<S, Partial<S>>>(state => (
5252
state.patch((a: A, s: S) => f(s, a))
5353
), update$)
5454
), this.plan)

src/fantasy/index.ts

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { Xstream } from './xstream'
22
export { FantasyX } from './fantasyx'
3+
34
export * from './typeclasses/applicative'
45
export * from './typeclasses/functor'
56
export * from './typeclasses/apply'
@@ -8,130 +9,3 @@ export * from './typeclasses/flatmap'
89
export * from './typeclasses/cartesian'
910
export * from './typeclasses/semigroup'
1011
export * from './typeclasses/traversable'
11-
// export function fromPlan<E extends Stream, I, S>(plan: Plan<E, I, S>): FantasyX<E, I, S, void> {
12-
// return new FantasyX<E, I, S, void>((intent$: Subject<E, I>) => {
13-
// let { update$, actions } = plan(intent$)
14-
// return {
15-
// actions,
16-
// update$: streamOps.map<Update<S>, State<S, void>>(
17-
// f => State.modify<S>(f), update$
18-
// )
19-
// }
20-
// })
21-
// }
22-
23-
// export function fromEvent<E extends Stream, I extends Event, S>(
24-
// type: string, name: string, defaultVal?: string
25-
// ): FantasyX<E, I, S, string> {
26-
// return new FantasyX<E, I, S, string>(intent$ => {
27-
// return {
28-
// update$: streamOps.merge<State<S, string>>(
29-
// typeof defaultVal != 'undefined' ? streamOps.just<State<S, string>>(State.pure<S, string>(defaultVal)) : streamOps.empty<State<S, string>>(),
30-
// streamOps.map<Event, State<S, string>>(
31-
// e => State.pure<S, string>((e.target as HTMLFormElement).value),
32-
// streamOps.filter<I>(i => {
33-
// let target = i.target as HTMLFormElement
34-
// return target.tagName == 'INPUT' && target.name == name
35-
// }, (intent$ as _<I>[E])))
36-
// )
37-
// }
38-
// })
39-
// }
40-
41-
// export function pure<E extends Stream, I, S, A>(a: A) {
42-
// return new FantasyX<E, I, S, A>(intent$ => {
43-
// return {
44-
// update$: streamOps.just<State<S, A>>(State.pure<S, A>(a))
45-
// }
46-
// })
47-
// }
48-
49-
// export function ap<E extends Stream, I, S, A, B>(
50-
// ff: FantasyX<E, I, S, (a: A) => B>,
51-
// fa: FantasyX<E, I, S, A>
52-
// ): FantasyX<E, I, S, B> {
53-
// return ff.combine((f, a) => f(a), fa)
54-
// }
55-
56-
// export function empty<E extends Stream, I, S, A>() {
57-
// return new FantasyX<E, I, S, A>(intent$ => {
58-
// return {
59-
// update$: streamOps.empty<State<S, A>>()
60-
// }
61-
// })
62-
// }
63-
64-
// export function map<E extends Stream, I, S, A, B>(
65-
// f: (s: A) => B, fa: FantasyX<E, I, S, A>
66-
// ): FantasyX<E, I, S, B> {
67-
// return fa.map(f)
68-
// }
69-
70-
71-
// export function traverse<E extends Stream, I, S, A>(
72-
// f: (a: A, index?: number) => FantasyX<E, I, S, A>, xs: A[]
73-
// ): FantasyX<E, I, S, A[]> {
74-
// return xs.reduce((acc, i, index) => acc.concat(f(i, index).map(x => [x])), pure<E, I, S, A[]>([]))
75-
// }
76-
77-
// export function fold<E extends Stream, I, S, A, B>(
78-
// f: (acc: B, i: A) => B, base: B, fa: FantasyX<E, I, S, A>
79-
// ): FantasyX<E, I, S, B> {
80-
// return fa.fold(f, base)
81-
// }
82-
83-
// export function lift<E extends Stream, I, S, A, B>(
84-
// f: (s: A) => B
85-
// ): (fa: FantasyX<E, I, S, A>) => FantasyX<E, I, S, B> {
86-
// return fa => fa.map(f)
87-
// }
88-
89-
// export function lift2<E extends Stream, I, S, A, B, C>(
90-
// f: (a: A, b: B) => C
91-
// ): (fa1: FantasyX<E, I, S, A>, fa2: FantasyX<E, I, S, B>) => FantasyX<E, I, S, C> {
92-
// return (fa1, fa2) => fa1.combine(f, fa2)
93-
// }
94-
95-
// export function lift3<E extends Stream, I, S, A, B, C, D>(
96-
// f: (a: A, b: B, c: C) => D
97-
// ): (fa1: FantasyX<E, I, S, A>, fa2: FantasyX<E, I, S, B>, fa3: FantasyX<E, I, S, C>) => FantasyX<E, I, S, D> {
98-
// return (fa1, fa2, fa3) => fa1.combine3(f, fa2, fa3)
99-
// }
100-
101-
// export function lift4<E extends Stream, I, S, A, B, C, D, F>(
102-
// f: (a: A, b: B, c: C, d: D) => F
103-
// ): (fa1: FantasyX<E, I, S, A>, fa2: FantasyX<E, I, S, B>, fa3: FantasyX<E, I, S, C>, fa4: FantasyX<E, I, S, D>) => FantasyX<E, I, S, F> {
104-
// return (fa1, fa2, fa3, fa4) => fa1.combine4(f, fa2, fa3, fa4)
105-
// }
106-
107-
// export function lift5<E extends Stream, I, S, A, B, C, D, F, G>(
108-
// f: (
109-
// s1: A,
110-
// s2: B,
111-
// s3: C,
112-
// s4: D,
113-
// s5: F
114-
// ) => G
115-
// ): (
116-
// fa1: FantasyX<E, I, S, A>,
117-
// fa2: FantasyX<E, I, S, B>,
118-
// fa3: FantasyX<E, I, S, C>,
119-
// fa4: FantasyX<E, I, S, D>,
120-
// fa5: FantasyX<E, I, S, F>
121-
// ) => FantasyX<E, I, S, G> {
122-
// return (fa1, fa2, fa3, fa4, fa5) => fa1.combine5(f, fa2, fa3, fa4, fa5)
123-
// }
124-
125-
// export function concat<E extends Stream, I, S, A>(
126-
// fa: FantasyX<E, I, S, A>,
127-
// fb: FantasyX<E, I, S, A>
128-
// ): FantasyX<E, I, S, A> {
129-
// return fa.concat(fb)
130-
// }
131-
132-
// export function merge<E extends Stream, I, S, A, B>(
133-
// fa: FantasyX<E, I, S, A>,
134-
// fb: FantasyX<E, I, S, B>
135-
// ): FantasyX<E, I, S, A | B> {
136-
// return fa.merge(fb)
137-
// }

src/fantasy/typeclasses/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ export function datatype(name: string) {
1414
}
1515

1616
export function kind(target: any) {
17-
if (isPrimitive(target))
17+
if (isPrimitive(target)) {
1818
return target.constructor.name
19-
return Reflect.getMetadata('design:type', target.constructor);
19+
}
20+
else {
21+
let tag = Reflect.getMetadata('design:type', target.constructor);
22+
if (tag) return tag
23+
throw `target ${target.constructor} is not a datatype, please decorate it with @datatype!`
24+
}
25+
2026
}
2127

2228
datatype('Array')(Array)

src/fantasy/xstream.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class Xstream<S extends Stream, I, A> {
6363
let state$ = this.streamS.runA(intent$)
6464
return {
6565
s: intent$,
66-
a: map<S, A, State<St, A>>((a: A) => Applicative.State.pure<St, A>(a), state$)
66+
a: streamOps.map<A, State<St, A>>((a: A) => Applicative.State.pure<St, A>(a), state$)
6767
}
6868
}))
6969
}
@@ -83,7 +83,7 @@ declare module './typeclasses/functor' {
8383

8484
export class XstreamFunctor implements Functor<"Xstream">{
8585
map<A, B>(f: (a: A) => B, fa: Xstream<Stream, any, A>): Xstream<Stream, any, B> {
86-
return new Xstream(Monad.State.map(sa => map<Stream, A, B>(f, sa), fa.streamS))
86+
return new Xstream(Monad.State.map(sa => streamOps.map<A, B>(f, sa), fa.streamS))
8787
}
8888
}
8989

@@ -94,7 +94,7 @@ export class XstreamCartesian implements Cartesian<"Xstream">{
9494
return new Xstream(
9595
FlatMap.State.flatMap(s1 => (
9696
Functor.State.map(s2 => (
97-
product(s1, s2)
97+
streamOps.combine((a, b) => [a, b], s1, s2)
9898
), fb.streamS)
9999
), fa.streamS))
100100
}
@@ -138,7 +138,7 @@ export class XstreamFlatMap extends XstreamApply {
138138
FlatMap.State.flatMap((a$: $<Stream, A>) => (
139139
map<"State", $<Stream, A>, $<Stream, B>>(i$ => {
140140
let sdf = (a: A) => f(a).streamS.runA(i$)
141-
return flatMap<Stream, A, B>(sdf, a$)
141+
return streamOps.flatMap<A, B>(sdf, a$)
142142
}, State.get<$<Stream, A>>())
143143
), fa.streamS)
144144
)

src/xs/most.ts

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
import { Stream as MostStream, empty, just, combineArray, combine, flatMap, fromPromise } from 'most'
22
import { sync, SyncSubject, Subject } from 'most-subject'
33
import { Subscription, StreamOps } from '.'
4-
import { Functor } from '../fantasy/typeclasses/functor'
5-
import { Cartesian } from '../fantasy/typeclasses/cartesian'
6-
import { Apply } from '../fantasy/typeclasses/apply'
7-
import { FlatMap } from '../fantasy/typeclasses/flatmap'
8-
import { Applicative } from '../fantasy/typeclasses/applicative'
9-
import { Monad } from '../fantasy/typeclasses/monad'
10-
import { datatype } from '../fantasy/typeclasses'
11-
12-
export const kind = 'MostStream'
13-
export type kind = typeof kind
144

155
declare module '.' {
166
interface S_<A> {
@@ -25,95 +15,6 @@ declare module '../fantasy/typeclasses' {
2515
}
2616
}
2717

28-
datatype(kind)(MostStream)
29-
30-
export class MostFunctor implements Functor<kind>{
31-
map<A, B>(f: (a: A) => B, fa: MostStream<A>): MostStream<B> {
32-
return fa.map(f)
33-
}
34-
}
35-
36-
declare module '../fantasy/typeclasses/functor' {
37-
namespace Functor {
38-
let MostStream: MostFunctor
39-
}
40-
}
41-
42-
Functor.MostStream = new MostFunctor
43-
44-
export class MostCartesian implements Cartesian<kind>{
45-
product<A, B>(fa: MostStream<A>, fb: MostStream<B>): MostStream<[A, B]> {
46-
return combine((a, b) => [a, b] as [A, B], fa, fb)
47-
}
48-
}
49-
50-
declare module '../fantasy/typeclasses/cartesian' {
51-
export namespace Cartesian {
52-
export let MostStream: MostCartesian
53-
}
54-
}
55-
56-
Cartesian.MostStream = new MostCartesian
57-
58-
export class MostApply implements Apply<kind> {
59-
ap<A, B>(fab: MostStream<(a: A) => B>, fa: MostStream<A>): MostStream<B> {
60-
return combine((ab, a) => ab(a), fab, fa)
61-
}
62-
map = Functor.MostStream.map
63-
product = Cartesian.MostStream.product
64-
}
65-
66-
declare module '../fantasy/typeclasses/apply' {
67-
namespace Apply {
68-
export let MostStream: MostApply
69-
}
70-
}
71-
72-
73-
export class MostFlatMap extends MostApply {
74-
flatMap<A, B>(f: (a: A) => MostStream<B>, fa: MostStream<A>): MostStream<B> {
75-
return flatMap(f, fa)
76-
}
77-
}
78-
79-
FlatMap.MostStream = new MostFlatMap
80-
81-
declare module '../fantasy/typeclasses/flatmap' {
82-
export namespace FlatMap {
83-
export let MostStream: MostFlatMap
84-
}
85-
}
86-
87-
export class MostApplicative extends MostApply {
88-
pure<A>(v: A): MostStream<A> {
89-
return just(v)
90-
}
91-
}
92-
93-
Applicative.MostStream = new MostApplicative
94-
95-
declare module '../fantasy/typeclasses/applicative' {
96-
export namespace Applicative {
97-
export let MostStream: MostApplicative
98-
}
99-
}
100-
101-
export class MostMonad implements Monad<kind> {
102-
flatMap = FlatMap.MostStream.flatMap
103-
map = Applicative.MostStream.map
104-
ap = Applicative.MostStream.ap
105-
pure = Applicative.MostStream.pure
106-
product = Applicative.MostStream.product
107-
}
108-
109-
Monad.MostStream = new MostMonad
110-
111-
declare module '../fantasy/typeclasses/monad' {
112-
export namespace Monad {
113-
export let MostStream: MostMonad
114-
}
115-
}
116-
11718
StreamOps.prototype.empty = empty
11819
StreamOps.prototype.just = just
11920

0 commit comments

Comments
 (0)