[Cycle.js] Hello World in Cycle.js
JS in Hello World cycle
2023-09-14 09:00:54 时间
Now you should have a good idea what Cycle.run does, and what the DOM Driver is. In this lesson, we will not build a toy version of Cycle.js anymore. Instead, we will learn how to use Cycle.js to solve problems. We will start by making a simple Hello world application.
const {label, input, hr, h1, div, makeDOMDriver} = CycleDOM; function main(sources) { // Read from driver, select '.field' class bind with input event. const inputEvent$ = sources.DOMM.select('.field').events('input'); // each input event will map to it's value // Because at first there is no input, so we mock one by using startWith('') const name$ = inputEvent$.map( ev => ev.target.value).startWith(''); return { // Each name event will output the CycleDOM DOMM: name$.map( name => { return div([ label('Name: '), input('.field',{type: 'text'}), hr(), h1(`Hello ${name}`) ]) }) }; } const drivers = { DOMM: makeDOMDriver('#app') } Cycle.run(main, drivers);
相关文章
- html如何只刷新页面指定,js控制页面刷新 JS刷新当前页面的几种方法总结
- prototype.js的系列文章——关于prototype.js
- javascript console_js decorator
- JS面试题-js新增基本数据类型BigInt
- js如何生成二维码_jquery 生成二维码无法识别
- JS对象转数组_js怎么把数组转成对象
- Js/JQuery生成不重复的UUID
- Touch 移动设备上的 手势识别 与 Js事件库
- get两个js小技能——JS截取视频第一帧&图片转Base64
- MySQL删除IN操作: 简易指南(mysql删除in)
- js动态往对象里边添加一项详解编程语言
- JS for in遍历对象属性
- JS document节点及其常用属性和方法
- 为 Debian 安装最新版本的 Node.js
- Oracle中使用EXISTS代替IN(oracle替换in)
- MySQL中IN语句的限制详解(mysql中in的限制)
- MySQL中的IN子句如何利用索引实现高效查询(mysql中in使用索引)
- 中利用IN语句检索Oracle数据库中的数据(in在oracle数据库)
- 控件开发时两种JS嵌入资源方式的使用方法
- js之弹出式窗口代码生成器
- 动态样式类封装JS代码
- js右下角与漂浮广告代码(兼容多浏览器)
- js延迟加载改变JS的位置加快网页加载速度
- ASP.NET中用js取CheckBoxList中值的方法实例
- js中的前绑定和后绑定详解
- 表格奇偶行设置不同颜色的核心JS代码
- 兼容主流浏览器的iframe自适应高度js脚本