惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
美团技术团队
P
Proofpoint News Feed
S
Schneier on Security
P
Privacy International News Feed
Last Week in AI
Last Week in AI
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tor Project blog
S
SegmentFault 最新的问题
Security Latest
Security Latest
月光博客
月光博客
A
About on SuperTechFans
Martin Fowler
Martin Fowler
A
Arctic Wolf
C
Cyber Attacks, Cyber Crime and Cyber Security
腾讯CDC
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
TaoSecurity Blog
TaoSecurity Blog
NISL@THU
NISL@THU
B
Blog RSS Feed
C
Cybersecurity and Infrastructure Security Agency CISA
Cyberwarzone
Cyberwarzone
V2EX - 技术
V2EX - 技术
Hacker News - Newest:
Hacker News - Newest: "LLM"
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
MyScale Blog
MyScale Blog
M
MIT News - Artificial intelligence
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
P
Proofpoint News Feed
F
Fortinet All Blogs
aimingoo的专栏
aimingoo的专栏
N
News and Events Feed by Topic
The Last Watchdog
The Last Watchdog
Engineering at Meta
Engineering at Meta
博客园 - 叶小钗
T
Tenable Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LINUX DO - 热门话题
Help Net Security
Help Net Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟 从Python转向Pharo https://blog.just4fun.site/post/iot/iot-open-source-projects/ Python异步编程笔记 https://blog.just4fun.site/post/iot/iot-open-source-hardware-community/ 万物积木化开发者社区 CodeLab ❤️ Blender Scratch3技术分析之云变量 API(第7篇) [译]对管道(Pipes)的偏爱 [译]提出正确的问题比得到正确答案更重要 蓝牙设备与Scratch3.0 创建你的第一个Scratch3.0 Extension Scratch3技术分析之项目内部数据(第6篇) Scratch3技术分析之社区 API(第5篇) Scratch3技术分析之User API(第4篇) Scratch3技术分析之项目主页API(第3篇) Scratch3技术分析之静态资源API(第2篇) Scratch3.0、micro:bit与Windows7 https://blog.just4fun.site/post/iot/zerynth-vs-micropython/ 核聚变、方所与半宅空间 可视化编程为何是个糟糕的主意 codelab.club周末聚会 关于codelab.club '下一件大事'是一个房间 Hungry Robot - Eat everything 编程作为一种思考方式 今日简史 史蒂夫·乔布斯传 罗素自选文集 https://blog.just4fun.site/post/edx/tianjin-scratch-ai/ https://blog.just4fun.site/post/edx/richie-cms-openedx/ 徒步武功山 WebUSB与micro:bit 积木化编程与3D场景 夜宿武功山顶 scratch3-adapter接入优必选Alpha系列机器人 https://blog.just4fun.site/post/edx/video-migration-note/ scratch3-adapter重构笔记 https://blog.just4fun.site/post/edx/edx-community-members/ 两种硬件编程风格的比较 使用micro:bit自制PPT翻页笔 柏拉图对话集 scratch3.0 + micro:bit 七月电影放映计划 非营利组织的管理 Screenly--用树莓派让任何屏幕变为可编程的数字标牌 以最佳实践开始你的Django项目 micro:bit与事件驱动 为Scratch3.0设计的插件系统(上篇) OCR应用一例 近两年读过的一些好书 blockly开发之使用python驱动浏览器中的turtle(2) 牛顿新传 文学理论入门 逻辑的引擎 人生的意义 blockly开发之生成并运行js代码(1) blockly开发之hello world(0) micro:bit使用笔记 神器之Termux https://blog.just4fun.site/post/iot/micropython-notes/ Cozmo what is this Scratch的前世今生 下段旅程 我行在远方 爆裂 途中杂记 https://blog.just4fun.site/post/edx/open-edx-startup/ cozmo系列之入门 - 有性格且可编程的机器人 PaperWeekly开发笔记 创业二三事
lively.next 备忘
种瓜 · 2020-11-22 · via 夜行人

文章目录

connect

lively.bindings – how to use connect

connect : 以声明方式定义源对象(source object)与目标对象(target object)之间的数据流连接。

1
2
3
4
5
6
7
// create source and target objects
var source = { sourceData: null };
var target = { targetData: null };
// connect source.sourceData -> target.targetData
connect(source, "sourceData", target, "targetData");
source.sourceData = 3;
target.targetData; // returns 3

Converter:

1
2
3
4
5
6
7
8
9
obj1 = { x: "foo" };
obj2 = { y: "123" };
connect(obj1, "x", obj2, "y", {
	converter: function (val) {
		return val % 7;
	},
});
obj1.x = 10;
obj2.y; //  3

Updater

1
2
3
4
5
6
7
8
obj = {};
connect(obj, "x", $world, "alert", {
	updater: function ($upd, val) {
		for (var i = 0; i < val; i++) $upd(i);
	},
});
obj.x = 3; // alerts 3 times
obj.x = 0; // no alert, we don't trigger anything

Disconnecting

1
disconnect(source, 'sourceData', target, 'targetData'); or disconnectAll(source)

新旧版本差异

新版本: 在场景(Scene)树里, 选中 morph 对象,之后创建 connection

快捷键(KeyBindings)

与 emacs 相似。

KeyBindings

自动补全

1
{keys: {win: "Ctrl-Space|Ctrl-Shift-P", mac: "Alt-Shift-Space|Alt-Space|Meta-Shift-P"}, command: "text completion"},

mac 下: option + space

lively.lang

lively.lang docs

提醒 : 内置对象(array、object)的特性与 Squeak 相似: Squeak 备忘

array

有许多 python-like 的便利操作。

以及 collection-like(与 Squeak 类似)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
var a = [1, 2, 3];
import { arr } from "lively.lang";
arr.max(a);

// create
arr.range(0, 5); // => [0,1,2,3,4,5]
arr.range(0, 10, 2); // => [0,2,4,6,8,10]
arr.withN(3, "Hello"); // => ["Hello","Hello","Hello"]
arr.genN(3, num.random); // => [46,77,95]

//invoke(array, method, arg1, arg2, arg3, arg4, arg5, arg6)
arr.invoke(["hello", "world"], "toUpperCase"); // => ["HELLO","WORLD"]

object

object docs

类似 squeak 里的 Dictionaries 对象

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import { obj } from "lively.lang";

// values
var obj1 = { x: 23, y: { z: 3 } };
obj.values(obj1); // => [22]

//inspect
obj.inspect(obj1);

// select

lively.classes

lively.classes: 支持实时开发的es6 class, 可动态修改,可序列化

eval-test

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { expect } from "mocha-es6";
// import { runEval, syncEval, defaultTopLevelVarRecorderName } from "lively.vm/index.js";
import * as vm from "lively.vm";
vm.syncEval("1+1"); //使 option + i
/*
{
  isError: false,
  isEvalResult: true,
  isPromise: false,
  promiseStatus: "unknown",
  promisedValue: undefined,
  value: 2,
  warnings: []
}
*/

/*
Promise({status: "fulfilled", value: {
  isError: false,
  isEvalResult: true,
  isPromise: false,
  promiseStatus: "unknown",
  promisedValue: undefined,
  value: 2,
  warnings: []
}})
*/

vm.runEval("1+2")
	.then((result) => expect(result.value).equal(3))
	.catch((err) => expect(false, "got error in runEval " + err));

lively.ast

docs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import * as ast from "lively.ast";
ast.stringify(ast.parse("1+2"));

ast.printAst(ast.parse("1+2"));

/*
:Program
\-.body[0]:ExpressionStatement
  \-.body[0].expression:BinaryExpression
    |-.body[0].expression.left:Literal
    \-.body[0].expression.right:Literal
*/

单独使用打包好的 lively.ast: lively.ast/examples

自定义模块

在 browser 中 创建/加载/修改 自定义模块

Hello World

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
export default class HelloWorld {
	constructor(a, b) {
		this.a = a;
		this.b = b;
	}

	log(x) {
		console.log(x);
	}
}

测试:

1
2
3
4
import HelloWorld from "HelloWorld/index.js";
let h = new HelloWorld("hello", "world");
h.a;
h.log("hi");

hello Morph

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
import { Morph, morph, Icon, touchInputDevice } from "lively.morphic";

class HelloMorph extends Morph {
	constructor(props) {
		super(props);
		console.log("log");
	}
}

let a = new HelloMorph({});
a.openInWindow();
// 问题: 目前的默认morph,样式不如 Squeak

Adapter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import EIMClient from "CodeLabAdapterClient/index.js";
let NODE_ID = "eim";
let HELP_URL = "https://adapter.codelab.club/";
let runtime = null;
let eim_client = new EIMClient(NODE_ID, HELP_URL, runtime);
//eim_client.adapter_base_client.emit_with_messageid('eim/extension_python', '1+1')

// promise
eim_client.adapter_base_client
	.emit_with_messageid("eim/extension_python", "1+1")
	.then((r) => {
		console.log(r);
	});

// async, return promise
async function emit_with_messageid(node_id, content){
	// todo resolve / reject -> timeout
 	let reply = await eim_client.adapter_base_client
	.emit_with_messageid(node_id, content);
	console.debug(`${reply}`);
 	return reply
}

emit_with_messageid("eim/extension_python", "1+1").then((data)=>{console.log(data)})

Linda

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import AdapterBaseClient from "CodeLabAdapterClient/codelab_adapter_base_lively.js";
let NODE_ID = "linda/js/client";
let HELP_URL = "https://adapter.codelab.club/user_guide/Linda/";
let runtime = null;
let adapter_client = new AdapterBaseClient(NODE_ID, HELP_URL, runtime);

await adapter_client.linda_out([1,2,3]).then((data)=>{console.log("linda",data); return data}) 

tuple = await adapter_client.linda_in(["hi", "lively", "*"]).then((data)=>{console.log("linda",data); return data})

tuple = await adapter_client.linda_in(["hi", "python", "from Lively"]).then((data)=>{console.log("linda",data); return data})

tuple = await adapter_client.linda_in(["hello", "lively", "*"]).then((data)=>{console.log("linda",data); return data})

await adapter_client.linda_in([1,2,5], 1000).then((data)=>{console.log("linda",data); return data}) //超时

参考