byteoss 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +109 -0
- package/index.js +147 -0
- package/oss/059e300c-9447-401a-9160-bc09b94a5bd4.css +516 -0
- package/oss/0fb02e11-31af-4551-a92e-b4457ad4ab0d.svg +3 -0
- package/oss/139daa0c-24fd-4be3-b9c6-8e51f96f6b96.svg +3 -0
- package/oss/1600dbb0-15a5-483d-bdbc-84971697ad90.svg +15 -0
- package/oss/177f61e2-3422-4c87-8110-ff1615758f91.css +153 -0
- package/oss/18cab5b9-4981-4274-8c5f-1978588297b0.png +0 -0
- package/oss/1c9abd94-340f-4c18-92a3-d28c61a16bbb.js +936 -0
- package/oss/258f066d-7574-491d-ba06-0f2e67db0773.js +1 -0
- package/oss/28225623-cdb8-4d7b-afe7-a25b9cdf4c79.svg +4 -0
- package/oss/2b103172-c38e-4c9c-b67c-753ede400c6b.js +1 -0
- package/oss/2cd0609f-d7a7-4c53-a277-79e8dec5dfc6.svg +4 -0
- package/oss/332d0e76-3c05-4285-af16-13e9f9bbcbed.css +431 -0
- package/oss/36a32028-256f-465d-be90-a65d1df04a90.js +1 -0
- package/oss/370921ea-2b94-4c18-9d1a-785aa58bef86.js +770 -0
- package/oss/3e98311d-bbf6-40d6-82b7-52b710aca34a.css +198 -0
- package/oss/40117c3a-1925-4250-90bf-f3ef878ee97d.svg +3 -0
- package/oss/469b8af5-1826-4f55-826f-56d57a896563.js +1 -0
- package/oss/49f08903-6594-475c-aab6-4c15b41ebc3a.svg +28 -0
- package/oss/4a5a9153-2bd7-443c-b628-aee3d4d55fd6.js +300 -0
- package/oss/4f100f7b-f956-431f-93f9-1e9e3a103574.css +197 -0
- package/oss/4f14fb89-2a43-49d4-89fe-c245508b451f.js +1 -0
- package/oss/50863606-18e8-4eaa-b738-6e98b7ff791f.css +513 -0
- package/oss/54a1eff8-ecd1-4604-956e-91e461d0f704.js +705 -0
- package/oss/554a3dbe-14c7-4349-956a-236b08a149f6.css +124 -0
- package/oss/5cb13f6f-423d-41e9-a081-ce544bf322f1.css +513 -0
- package/oss/5fd8e893-8b05-452f-b914-26965c19fd31.svg +1 -0
- package/oss/6016b5f9-4473-44d9-9373-c761278cc244.js +2909 -0
- package/oss/630ebd92-9296-4c85-a18c-954545b9716b.mp4 +0 -0
- package/oss/66127685-903b-4261-bc3a-887459229b79.js +90 -0
- package/oss/6bf3a690-882e-47b2-a3bf-07600e1067d9.svg +1 -0
- package/oss/6d15d999-42a6-48f8-85dc-d6dd2547d33c.svg +10 -0
- package/oss/72ca2a33-968f-4bc4-ba39-417aca989e2a.svg +40 -0
- package/oss/74a7f15c-cf9e-41e5-a649-bc7a9960b89d.js +936 -0
- package/oss/754fca20-6995-4b15-bf56-2202c2107f41.svg +1 -0
- package/oss/7dbeba7d-92dc-4f24-981f-6ee5988326a3.js +90 -0
- package/oss/7ec89667-7160-44da-8c5d-8cb2e5b6ed51.css +144 -0
- package/oss/80254c08-1b12-4f32-bec9-b56251fb7b6e.svg +14 -0
- package/oss/80c9635a-2d99-483a-b46a-eec29d831dbc.svg +1 -0
- package/oss/83982b15-f2af-4c7d-98d1-9885c934adee.css +153 -0
- package/oss/842d27d8-4c7d-4655-bd81-d19376b9c779.ttf +0 -0
- package/oss/86e16498-0990-4f5f-9c78-919d6e901b3e.png +0 -0
- package/oss/871ce06b-adf2-4d23-893e-c929ed0dc660.css +1079 -0
- package/oss/875441a7-46aa-4510-b395-59d32129b643.js +84 -0
- package/oss/886aaec0-d95a-44c0-a809-b611c3a385bc.svg +1 -0
- package/oss/8870cb0a-075f-4296-8855-cf708905377f.js +51 -0
- package/oss/88a1fdfb-b313-4021-8c2e-97db3dddd4af.svg +26 -0
- package/oss/8bd1a260-f002-42d3-a288-9ec0270490ea.svg +14 -0
- package/oss/8d1ac209-5712-43a7-9d86-c4a1b4d6734a.json +1 -0
- package/oss/917711d3-9f92-4b63-804c-a17050b72502.svg +1 -0
- package/oss/92122f36-32a3-44ad-81f9-96427ad7d999.svg +4 -0
- package/oss/945aebff-92e3-4f5a-b3e1-9d891c525d95.js +19 -0
- package/oss/945aebff-92e3-4f5a-b3e1-9d891c525d95_bak.js +19 -0
- package/oss/94b77c89-093d-48ae-b363-9f6648f91ab6.css +2435 -0
- package/oss/9697873a-4c40-401e-addd-3736815acf10.svg +3 -0
- package/oss/9bd56993-3d11-4a5c-a682-a95e527da09e.svg +1 -0
- package/oss/9fa42c0c-617c-44a2-9bb9-aec8994af673.svg +1 -0
- package/oss/a25bc2e8-28e3-4bd2-b0cf-c4f577934119.svg +3 -0
- package/oss/a2e59c39-138a-4d1e-84c8-bc058454133f.js +434 -0
- package/oss/a5535c26-8363-4625-afa2-8fbbee4dab40.css +124 -0
- package/oss/a6a7c636-670b-4f99-aa6b-e5cb6f029327.ico +0 -0
- package/oss/a6f63612-b3d1-4aba-bf5f-0cd3055a7251.svg +1 -0
- package/oss/a85345e2-b625-4917-8c47-d85503226015.svg +12 -0
- package/oss/ab70067a-ed3f-4d8c-8776-cd1a7b67097d.svg +8 -0
- package/oss/abe3279f-b713-403f-b0d1-7efa24502c11.css +2251 -0
- package/oss/b10e7a02-f948-4c79-98a1-504ef025d37a.ttf +0 -0
- package/oss/b43dabdf-cf3d-4e74-aaec-46b451089b4b.svg +4 -0
- package/oss/b4e5962d-0b64-4667-89aa-bdbfc967f9d5.svg +12 -0
- package/oss/b7633fb4-4845-45b1-b516-b76bc0b31692.svg +10 -0
- package/oss/bd64bd8e-ad36-4b30-bc3f-047f0b5472af.eot +0 -0
- package/oss/be75e4b2-9d84-41a1-b2ad-941100c6eb9f.svg +1 -0
- package/oss/bf600662-21bc-427a-a3ff-c7148bfb7a37.css +516 -0
- package/oss/bktjgd.js +0 -0
- package/oss/bktjwb.js +0 -0
- package/oss/c1c43d05-3fe7-4f66-92c3-a4e673de15d2.css +126 -0
- package/oss/c40e78e1-28a9-403f-9bb6-6a61bb759f3c.svg +9 -0
- package/oss/c5e67efa-03ef-4285-9eb2-979d24b97b0a.js +505 -0
- package/oss/ca88122c-71f0-4bdb-801b-845c3e2416c0.js +57 -0
- package/oss/ce7d2a57-04d3-4320-95de-a1acb29c2299.svg +1 -0
- package/oss/cf261a0a-f683-4e12-92c1-98c42038da76.js +301 -0
- package/oss/d13ba061-af1c-420f-a700-4a8c175a6d90.js +51 -0
- package/oss/d820804f-af30-4364-b882-9d7b23e98353.js +1 -0
- package/oss/dae77962-f0f3-487f-bfff-1251e44b3d98.js +313 -0
- package/oss/db0b6693-9a13-4a89-9c67-82a5c2208ed9.svg +1 -0
- package/oss/dd3a7016-cf8c-493c-ba87-c7da470f9307.svg +1 -0
- package/oss/dd4c56f1-700e-49b8-a40f-530ed2e06934.svg +1 -0
- package/oss/de85749c-9ab2-4798-a080-1dafbd2bb89a.css +393 -0
- package/oss/dfd0db36-8259-4d6e-a426-7c1167c7657d.svg +18 -0
- package/oss/e082736c-726c-4029-b3ce-6c89d83ad9ce.css +3177 -0
- package/oss/e0efdb0b-2cf8-41fe-b862-7560a8d957e3.js +193 -0
- package/oss/e1d3a1a8-c200-47de-bba9-b92aa112010b.svg +1 -0
- package/oss/e937b5e0-2285-474e-84e7-5c478f305280.js +775 -0
- package/oss/ed850ceb-a7a3-47f4-9d2e-d6fd2666a8c9.js +936 -0
- package/oss/ee0c80ad-d7cb-464f-aa4a-a7f439d76ae8.js +665 -0
- package/oss/ef62fbf5-a876-4112-8062-c97b5341f1b9.css +653 -0
- package/oss/f343adb3-110f-445e-80b4-abca81ff558a.js +787 -0
- package/oss/f4d90992-79bf-4a51-a2d7-7d556fac63d3.js +1 -0
- package/oss/f59f0ec0-974b-496d-a518-dfb79e0ecec0.js +51 -0
- package/oss/f68472c9-1d02-451a-be1f-6d5f0fa2c6fd.css +145 -0
- package/oss/f7b46b4d-6311-4416-95b0-e18ad577c166.css +1 -0
- package/oss/home.css +459 -0
- package/oss/mjandjlbgd.js +0 -0
- package/oss/mjandjlbwb.js +0 -0
- package/package.json +17 -0
package/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
����һ����̬��Դ��
|
2
|
+
|
3
|
+
## ��װ
|
4
|
+
|
5
|
+
```
|
6
|
+
yarn add topic
|
7
|
+
```
|
8
|
+
|
9
|
+
# ����
|
10
|
+
|
11
|
+
### publish
|
12
|
+
|
13
|
+
�����¼�
|
14
|
+
|
15
|
+
```typescript
|
16
|
+
import { topic } from 'topic';
|
17
|
+
|
18
|
+
topic.publish('name', 'message');
|
19
|
+
```
|
20
|
+
|
21
|
+
### subscribe
|
22
|
+
|
23
|
+
�����¼�
|
24
|
+
|
25
|
+
```typescript
|
26
|
+
topic.subscribe('who', (name, age) => {
|
27
|
+
console.log('Hello' + name + ', are you ' + age + 'old?');
|
28
|
+
});
|
29
|
+
|
30
|
+
topic.publish('who', 'Tom', 12);
|
31
|
+
```
|
32
|
+
|
33
|
+
### subscribeOnce
|
34
|
+
|
35
|
+
�����¼�������һ�κ�����ȡ��
|
36
|
+
|
37
|
+
```typescript
|
38
|
+
topic.subscribeOnce('who', (name) => {
|
39
|
+
console.log('Hello ' + name);
|
40
|
+
});
|
41
|
+
|
42
|
+
// ��һ���������յ���Ϣ
|
43
|
+
topic.publish('who', 'Tom');
|
44
|
+
// û�ж�������
|
45
|
+
topic.publish('who', 'Tom');
|
46
|
+
```
|
47
|
+
|
48
|
+
### unsubscribe
|
49
|
+
|
50
|
+
ȡ�������¼�
|
51
|
+
|
52
|
+
```typescript
|
53
|
+
const handle = topic.subscribe('who', (name) => {
|
54
|
+
console.log('Hello ' + name);
|
55
|
+
});
|
56
|
+
|
57
|
+
// ��һ���������յ���Ϣ
|
58
|
+
topic.publish('who', 'Tom');
|
59
|
+
// ��һ���������յ���Ϣ
|
60
|
+
topic.publish('who', 'John');
|
61
|
+
|
62
|
+
handle.unsubscribe();
|
63
|
+
// û�ж�������
|
64
|
+
topic.publish('who', 'Tom');
|
65
|
+
```
|
66
|
+
|
67
|
+
### keep + release
|
68
|
+
|
69
|
+
���������¼�
|
70
|
+
|
71
|
+
```typescript
|
72
|
+
const sub1 = topic.subscribe('who', (name) => {
|
73
|
+
console.log('Hello ' + name);
|
74
|
+
});
|
75
|
+
|
76
|
+
// sub1 �յ���Ϣ
|
77
|
+
const handle = topic.keep('who', true, 'Tom');
|
78
|
+
|
79
|
+
// sub2 �����յ���Ϣ
|
80
|
+
const sub2 = topic.subscribe('who', (name) => {});
|
81
|
+
|
82
|
+
// sub3 �����յ���Ϣ
|
83
|
+
const sub3 = topic.subscribe('who', (name) => {});
|
84
|
+
|
85
|
+
handle.release();
|
86
|
+
|
87
|
+
// sub3 û���յ���Ϣ
|
88
|
+
const sub3 = topic.subscribe('who', (name) => {});
|
89
|
+
```
|
90
|
+
|
91
|
+
# ʹ�� TS �����Զ����¼�
|
92
|
+
|
93
|
+
ʵ����� topic ���ǻ������ŵģ�������ȫ��ҵ����߾ֲ�ҵ��
|
94
|
+
|
95
|
+
```typescript
|
96
|
+
import { Topic } from 'topic';
|
97
|
+
|
98
|
+
const customTopic = new Topic<{
|
99
|
+
foo: [name: string];
|
100
|
+
bar: [name: string, age: number];
|
101
|
+
// ������봫�����ɿص��¼����ƣ���ȡ����������ע��
|
102
|
+
// [more: string]: any[];
|
103
|
+
}>();
|
104
|
+
|
105
|
+
// ���ڱ༭������ʾ��name��������
|
106
|
+
customTopic.subscribe('foo', (name) => {});
|
107
|
+
// ���ڱ༭��֪���ڶ�������Ӧ�ô�ʲô������
|
108
|
+
customTopic.publish('foo', 'Tom');
|
109
|
+
```
|
package/index.js
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
"use strict";
|
2
|
+
function _classCallCheck(instance, Constructor) {
|
3
|
+
if (!(instance instanceof Constructor)) {
|
4
|
+
throw new TypeError("Cannot call a class as a function");
|
5
|
+
}
|
6
|
+
}
|
7
|
+
function _defineProperties(target, props) {
|
8
|
+
for(var i = 0; i < props.length; i++){
|
9
|
+
var descriptor = props[i];
|
10
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
11
|
+
descriptor.configurable = true;
|
12
|
+
if ("value" in descriptor) descriptor.writable = true;
|
13
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
14
|
+
}
|
15
|
+
}
|
16
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
17
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
18
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
19
|
+
return Constructor;
|
20
|
+
}
|
21
|
+
Object.defineProperty(exports, "__esModule", {
|
22
|
+
value: true
|
23
|
+
}); // index.ts
|
24
|
+
var when = function(deps) {
|
25
|
+
return typeof deps === "boolean" ? deps : deps();
|
26
|
+
};
|
27
|
+
var aps = Array.prototype.slice;
|
28
|
+
var counter = 0;
|
29
|
+
var Topic = /*#__PURE__*/ function() {
|
30
|
+
function _class() {
|
31
|
+
_classCallCheck(this, _class);
|
32
|
+
this.listeners = {};
|
33
|
+
this.origins = {};
|
34
|
+
this.keeps = [];
|
35
|
+
}
|
36
|
+
_createClass(_class, [
|
37
|
+
{
|
38
|
+
key: "publish",
|
39
|
+
value: function publish() {
|
40
|
+
var name = arguments[0];
|
41
|
+
var args = aps.call(arguments, 1);
|
42
|
+
var listeners = this.origins[name] = this.listeners[name];
|
43
|
+
if (!listeners || !listeners.length) {
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
for(var i = 0; i < listeners.length; ++i){
|
47
|
+
listeners[i].fn.apply(null, args);
|
48
|
+
}
|
49
|
+
this.origins[name] = void 0;
|
50
|
+
}
|
51
|
+
},
|
52
|
+
{
|
53
|
+
key: "subscribeOnce",
|
54
|
+
value: function subscribeOnce(name, fn) {
|
55
|
+
var executed = false;
|
56
|
+
var ref = {};
|
57
|
+
ref.token = this.subscribe(name, function() {
|
58
|
+
fn.apply(null, arguments);
|
59
|
+
if (ref.token) {
|
60
|
+
ref.token.unsubscribe();
|
61
|
+
} else {
|
62
|
+
executed = true;
|
63
|
+
}
|
64
|
+
});
|
65
|
+
if (executed) {
|
66
|
+
ref.token.unsubscribe();
|
67
|
+
}
|
68
|
+
return ref.token;
|
69
|
+
}
|
70
|
+
},
|
71
|
+
{
|
72
|
+
key: "subscribe",
|
73
|
+
value: function subscribe(name, fn) {
|
74
|
+
var token = "Token_" + counter++;
|
75
|
+
var listeners = this.listeners[name];
|
76
|
+
if (listeners) {
|
77
|
+
var origin = this.origins[name];
|
78
|
+
if (origin && listeners === origin) {
|
79
|
+
listeners = this.listeners[name] = listeners.slice(0);
|
80
|
+
}
|
81
|
+
} else {
|
82
|
+
listeners = this.listeners[name] = [];
|
83
|
+
}
|
84
|
+
listeners.push({
|
85
|
+
token: token,
|
86
|
+
fn: fn
|
87
|
+
});
|
88
|
+
if (this.keeps.length) {
|
89
|
+
var keeps = this.keeps.filter(function(item) {
|
90
|
+
return item.name === name && when(item.shouldPublish);
|
91
|
+
});
|
92
|
+
for(var i = 0; i < keeps.length; ++i){
|
93
|
+
fn.apply(null, keeps[i].args);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
return {
|
97
|
+
unsubscribe: this.unsubscribe.bind(this, name, token)
|
98
|
+
};
|
99
|
+
}
|
100
|
+
},
|
101
|
+
{
|
102
|
+
key: "keep",
|
103
|
+
value: function keep() {
|
104
|
+
var name = arguments[0];
|
105
|
+
var shouldPublish = arguments[1];
|
106
|
+
var args = aps.call(arguments, 2);
|
107
|
+
var token = "Token_" + counter++;
|
108
|
+
when(shouldPublish) && this.publish.apply(this, [
|
109
|
+
name
|
110
|
+
].concat(args));
|
111
|
+
this.keeps.push({
|
112
|
+
shouldPublish: shouldPublish,
|
113
|
+
token: token,
|
114
|
+
name: name,
|
115
|
+
args: args
|
116
|
+
});
|
117
|
+
return {
|
118
|
+
release: this.release.bind(this, token)
|
119
|
+
};
|
120
|
+
}
|
121
|
+
},
|
122
|
+
{
|
123
|
+
key: "unsubscribe",
|
124
|
+
value: function unsubscribe(name, token) {
|
125
|
+
var listeners = this.listeners[name];
|
126
|
+
if (!listeners || !listeners.length) {
|
127
|
+
return;
|
128
|
+
}
|
129
|
+
this.listeners[name] = listeners.filter(function(item) {
|
130
|
+
return item.token !== token;
|
131
|
+
});
|
132
|
+
}
|
133
|
+
},
|
134
|
+
{
|
135
|
+
key: "release",
|
136
|
+
value: function release(token) {
|
137
|
+
this.keeps = this.keeps.filter(function(item) {
|
138
|
+
return item.token !== token;
|
139
|
+
});
|
140
|
+
}
|
141
|
+
}
|
142
|
+
]);
|
143
|
+
return _class;
|
144
|
+
}();
|
145
|
+
var topic = new Topic();
|
146
|
+
exports.Topic = Topic;
|
147
|
+
exports.topic = topic;
|