Skip to content

Commit ecef0f5

Browse files
committed
big refactor
1 parent 95aecc6 commit ecef0f5

File tree

883 files changed

+14156
-8183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

883 files changed

+14156
-8183
lines changed

.prettierignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
src/test/**
2-
31
lib
42

53
build

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The unit Programming Language was developed in close junction to the unit Progra
1414

1515
unit is similar in concept to the Unix shell; for a seasoned programmer, unit should feel like the 2D evolution of the Command Line Interface (CLI) where units' (commands) inputs and outputs (stdin/stdout/stderr) can be piped together into a graph (script). In fact, unit can be thought of as a re-exploration of the [Unix Philosophy](https://en.wikipedia.org/wiki/Unix_philosophy) in the context of modern Software Engineering.
1616

17-
The unit system is set to grow into a modern and approachable Web Operating System, which is sandboxed by default, enabling a new era of Software Sharing and Collaboration.
17+
The unit system is set to grow into a simple and approachable Web Operating System, which is sandboxed by default, enabling a new era of Software Sharing and Collaboration.
1818

1919
The broader Design Philosophy behind unit is discussed in [Concept](src/docs/concept/README.md).
2020

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
padding: 0;
190190
width: 100%;
191191
height: 100%;
192+
font-size: 14px;
192193
box-sizing: border-box;
193194
background: transparent;
194195
/* touch-action: none; */

src/AsyncWorker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Callback } from './Callback'
21
import {
32
$C,
43
$C_C,
@@ -52,7 +51,8 @@ import {
5251
} from './interface/async/$V'
5352
import { AsyncWrap } from './interface/async/AsyncWrap'
5453
import { RemotePort } from './RemotePort'
55-
import { Unlisten } from './Unlisten'
54+
import { Callback } from './types/Callback'
55+
import { Unlisten } from './types/Unlisten'
5656

5757
export function AsyncWorker(client: RemotePort, _: string[]): any {
5858
return AsyncWrap(client, _, {

src/Class/$.ts

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
import { EventEmitter_ } from '../EventEmitter'
1+
import { EventEmitter, EventEmitter_EE } from '../EventEmitter'
22
import { deleteGlobalRef, setGlobalRef } from '../global'
3-
import { $_ } from '../interface/$_'
4-
import { PO } from '../interface/PO'
3+
import { Pod } from '../pod'
54
import { System } from '../system'
6-
import { Unlisten } from '../Unlisten'
7-
import { Dict } from './../types/Dict'
5+
import { Dict } from '../types/Dict'
86

9-
export class $ extends EventEmitter_ implements $_ {
10-
public __: string[] = []
11-
public __id: string
7+
export type $_EE = { destroy: [] }
8+
9+
export type $Events<_EE extends Dict<any[]>> = EventEmitter_EE<_EE & $_EE> &
10+
$_EE
1211

13-
public __pod: PO | null = null
14-
public __system: System | null = null
12+
export class $<
13+
_EE extends $Events<_EE> & Dict<any[]> = $Events<$_EE>
14+
> extends EventEmitter<_EE> {
15+
public __: string[] = []
16+
public __pod: Pod
17+
public __system: System
1518
public __global_id: string
1619

17-
constructor(__system: System = null) {
20+
constructor(system: System, pod: Pod) {
1821
super()
1922

20-
this.__system = __system
23+
this.__system = system
24+
this.__pod = pod
2125

22-
if (this.__system) {
23-
this.__global_id = setGlobalRef(this.__system, this)
24-
}
26+
this.__global_id = setGlobalRef(this.__system, this)
2527
}
2628

2729
getGlobalId(): string {
@@ -36,40 +38,12 @@ export class $ extends EventEmitter_ implements $_ {
3638
return this.__system
3739
}
3840

39-
refPod(): PO {
41+
refPod(): Pod {
4042
return this.__pod
4143
}
4244

43-
attach(__system: System): void {
44-
// console.log('$', 'attach', __system, $pod)
45-
46-
if (__system === this.__system) {
47-
return
48-
}
49-
50-
this.__system = __system
51-
52-
this.__global_id = setGlobalRef(this.__system, this)
53-
54-
this.emit('_attach', __system)
55-
}
56-
57-
dettach(): void {
58-
if (this.__system) {
59-
deleteGlobalRef(this.__system, this.__global_id)
60-
this.__global_id = undefined
61-
}
62-
63-
this.__system = null
64-
this.__pod = null
65-
66-
this.emit('_dettach')
67-
}
68-
6945
destroy() {
70-
if (this.__system) {
71-
deleteGlobalRef(this.__system, this.__global_id)
72-
}
46+
deleteGlobalRef(this.__system, this.__global_id)
7347

7448
this.emit('destroy')
7549
}

src/Class/Element/Element.ts renamed to src/Class/Element/index.ts

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,59 @@ import {
1111
removeChild,
1212
removeParentChild,
1313
unregisterParentRoot,
14-
unregisterRoot
14+
unregisterRoot,
1515
} from '../../component/method'
16-
import { C } from '../../interface/C'
16+
import { C_EE } from '../../interface/C'
17+
import { Component_ } from '../../interface/component'
1718
import { E } from '../../interface/E'
19+
import { Pod } from '../../pod'
1820
import { System } from '../../system'
1921
import { Dict } from '../../types/Dict'
2022
import { UnitClass } from '../../types/UnitClass'
2123
import { forEach } from '../../util/array'
22-
import { Stateful } from '../Stateful'
24+
import { Stateful, StatefulEvents } from '../Stateful'
2325
import { ION, Opt } from '../Unit'
2426

25-
export class Element<I = any, O = any> extends Stateful<I, O> implements E {
26-
__ = ['U', 'C', 'V']
27+
export type Element_EE = C_EE & { call: [{ method: string; data: any[] }] }
2728

28-
public element = true
29-
30-
public _children: E[] = []
31-
public _root: C[] = []
32-
public _parent_root: C[] = []
33-
public _parent_children: C[] = []
29+
export type ElementEvents<_EE extends Dict<any[]>> = StatefulEvents<
30+
_EE & Element_EE
31+
> &
32+
Element_EE
3433

34+
export class Element<
35+
I = any,
36+
O = any,
37+
_J extends Dict<any> = {},
38+
_EE extends ElementEvents<_EE> & Dict<any[]> = ElementEvents<Element_EE>
39+
>
40+
extends Stateful<I, O, {}, _EE>
41+
implements E
42+
{
43+
__ = ['U', 'C', 'J', 'V']
3544

36-
public _slot: Dict<C> = {}
45+
public element = true
3746

38-
constructor({ i = [], o = [] }: ION, opt: Opt = {}, system: System = null) {
47+
public _children: Component_[] = []
48+
public _root: Component_[] = []
49+
public _parent_root: Component_[] = []
50+
public _parent_children: Component_[] = []
51+
public _slot: Dict<Component_> = {}
52+
53+
constructor(
54+
{ i = [], o = [] }: ION,
55+
opt: Opt = {},
56+
system: System,
57+
pod: Pod
58+
) {
3959
super(
4060
{
4161
i,
4262
o,
4363
},
4464
opt,
45-
system
65+
system,
66+
pod
4667
)
4768

4869
this.addListener('play', this._play)
@@ -53,27 +74,27 @@ export class Element<I = any, O = any> extends Stateful<I, O> implements E {
5374
}
5475
}
5576

56-
registerRoot(component: C): number {
77+
registerRoot(component: Component_): void {
5778
return registerRoot(this, this._root, component)
5879
}
5980

60-
unregisterRoot(component: C): void {
81+
unregisterRoot(component: Component_): void {
6182
return unregisterRoot(this, this._root, component)
6283
}
6384

64-
registerParentRoot(component: C, slotName: string): void {
85+
registerParentRoot(component: Component_, slotName: string): void {
6586
return registerParentRoot(this, this._parent_root, component, slotName)
6687
}
6788

68-
unregisterParentRoot(component: C): void {
89+
unregisterParentRoot(component: Component_): void {
6990
return unregisterParentRoot(this, this._parent_root, component)
7091
}
7192

72-
appendParentChild(component: C<any, any>, slotName: string): void {
93+
appendParentChild(component: Component_, slotName: string): void {
7394
return appendParentChild(this, this._parent_children, component, slotName)
7495
}
7596

76-
removeParentChild(component: C<any, any>): void {
97+
removeParentChild(component: Component_): void {
7798
return removeParentChild(this, this._parent_children, component)
7899
}
79100

@@ -97,15 +118,15 @@ export class Element<I = any, O = any> extends Stateful<I, O> implements E {
97118
throw pullChild(this, this._children, at)
98119
}
99120

100-
refChild(at: number): C {
121+
refChild(at: number): Component_ {
101122
return refChild(this, this._children, at)
102123
}
103124

104-
refChildren(): C[] {
125+
refChildren(): Component_[] {
105126
return refChildren(this, this._children)
106127
}
107128

108-
refSlot(slotName: string): C<any, any> {
129+
refSlot(slotName: string): Component_ {
109130
const slot = this._slot[slotName]
110131

111132
if (slot) {

src/Class/Functional/index.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
import { Primitive } from '../../Primitive'
1+
import { Pod } from '../../pod'
2+
import { Primitive, PrimitiveEvents } from '../../Primitive'
23
import { System } from '../../system'
34
import forEachKeyValue from '../../system/core/object/ForEachKeyValue/f'
5+
import { Dict } from '../../types/Dict'
46
import { filterObj } from '../../util/object'
57
import { ION, Opt } from '../Unit'
68
import { Done } from './Done'
79

8-
export class Functional<I = {}, O = {}> extends Primitive<I, O> {
10+
export type Functional_EE = {}
11+
12+
export type FunctionalEvents<_EE extends Dict<any[]>> = PrimitiveEvents<
13+
_EE & Functional_EE
14+
> &
15+
Functional_EE
16+
17+
export class Functional<
18+
I = {},
19+
O = {},
20+
_EE extends FunctionalEvents<_EE> = FunctionalEvents<Functional_EE>
21+
> extends Primitive<I, O, _EE> {
922
private _looping: boolean = false
1023

11-
constructor({ i, o }: ION = {}, opt: Opt = {}, system: System = null) {
12-
super({ i, o }, opt, system)
24+
constructor({ i, o }: ION = {}, opt: Opt = {}, system: System, pod: Pod) {
25+
super({ i, o }, opt, system, pod)
1326

1427
this.addListener('take_err', () => {
1528
if (this._looping) {

0 commit comments

Comments
 (0)