<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sivan&#039;s Blog</title>
	<atom:link href="https://lightcss.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://lightcss.com</link>
	<description>一念心清凈，走進極樂境。</description>
	<lastBuildDate>Tue, 30 Apr 2024 03:21:29 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">48344701</site>	<item>
		<title>阅读清单 #3</title>
		<link>https://lightcss.com/reading-list-3/</link>
					<comments>https://lightcss.com/reading-list-3/#comments</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sun, 17 May 2020 14:33:09 +0000</pubDate>
				<category><![CDATA[前端开发]]></category>
		<category><![CDATA[阅读清单]]></category>
		<guid isPermaLink="false">https://lightcss.com/?p=743</guid>

					<description><![CDATA[最近使用 Storybook 搭了个环境测试组件，为了一个简单的功能愣是四处翻文档和源码折腾了一下午才搞定。再也不想用 Webpack 了。&#x1f643;]]></description>
										<content:encoded><![CDATA[
<p>最近使用 Storybook 搭了个环境测试组件，为了一个简单的功能愣是四处翻文档和源码折腾了一下午才搞定。再也不想用 Webpack 了。&#x1f643;</p>



<div class="wp-block-jetpack-markdown"><ul>
<li><a href="https://moderncss.dev/">Modern CSS Solutions</a>：对组件开发者很有帮助的系列文章。</li>
<li><a href="https://web.dev/optimize-cls/">Optimize Cumulative Layout Shift</a>：Addy Osmani 关于通过改善布局抖动提升用户体验的专题。</li>
<li><a href="https://flaviocopes.com/deno/">The Deno Handbook: a concise introduction to Deno &#x1f995;</a>：<a href="https://deno.land/">Deno</a> 本周发布了 1.0，这是一个手册。你还学的动吗？</li>
<li><a href="https://codepen.io/michellebarker/pen/xxwLpRG">Intersection Observer Visualizer</a></li>
<li><a href="https://github.com/yemount/pose-animator/">Pose Animator</a>：基于 Tenseorflow.js 实现的实时人脸动画。</li>
<li><a href="https://reefjs.com/">Reef</a>：又一个 anti-framework 的轮子。</li>
<li><a href="https://blush.design/">Blush</a>：结合 Figma 生成插画的小插件。</li>
<li><a href="https://css-irl.info/exciting-things-on-the-horizon-for-css-layout/">Exciting Things on the Horizon For CSS Layout</a>：Chrome 升级了它的 Grid 调试工具，以及…</li>
</ul>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/reading-list-3/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">743</post-id>	</item>
		<item>
		<title>阅读清单 #2</title>
		<link>https://lightcss.com/reading-list-2/</link>
					<comments>https://lightcss.com/reading-list-2/#comments</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sun, 03 May 2020 13:52:42 +0000</pubDate>
				<category><![CDATA[前端开发]]></category>
		<category><![CDATA[阅读清单]]></category>
		<guid isPermaLink="false">https://lightcss.com/?p=725</guid>

					<description><![CDATA[不知不觉五一小长假已过半，上个月部门作了很大的结构调整，我的团队成员构成也更加丰富，大家快乐又 &#8230; <a href="https://lightcss.com/reading-list-2/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[
<p>不知不觉五一小长假已过半，上个月部门作了很大的结构调整，我的团队成员构成也更加丰富，大家快乐又忙碌。最近认真阅读的文章比较少，先发一小部分吧。最近给我的 Mac Pro（2013）换上了 LG UltraFine 4K，真香呐！&#x1f601;</p>



<div class="wp-block-jetpack-markdown"><ul>
<li><a href="https://css-tricks.com/ligature-icons/">Ligature Icons via Pseudo Elements and Icon Fonts</a>：最近看到 Material Design 通过 Font Ligature 实现的 <a href="https://github.com/material-components/material-components-web-components/tree/master/packages/icon">Icon</a> 组件很有意思，这篇是原理的介绍。</li>
<li><a href="https://hackernoon.com/how-to-manage-reusable-ui-components-iu1x32up">How to Manage Reusable UI Components</a></li>
<li><a href="https://blog.bitsrc.io/versioning-independent-ui-components-why-and-how-7ea60d8be5f2">The Case for Versioning Independent UI Components</a></li>
<li><a href="http://www.js-craft.io/blog/making-a-responsive-css-grid-layout-with-just-3-properties/">Making a responsive CSS grid layout with just 3 properties</a></li>
<li><a href="https://fossheim.io/writing/posts/css-box-shadow-animation/">How to create an accordion hover effect with box-shadows</a></li>
<li><a href="https://cssmondrian.com/">CSS Mondrian</a></li>
</ul>
<p>-- EOF --</p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/reading-list-2/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">725</post-id>	</item>
		<item>
		<title>阅读清单 #1</title>
		<link>https://lightcss.com/reading-list-1/</link>
					<comments>https://lightcss.com/reading-list-1/#comments</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Fri, 13 Mar 2020 12:00:00 +0000</pubDate>
				<category><![CDATA[前端开发]]></category>
		<category><![CDATA[阅读清单]]></category>
		<guid isPermaLink="false">https://lightcss.com/?p=720</guid>

					<description><![CDATA[最近受疫情影响一直在远程办公，很多项目推进节奏都有所放缓，也有更多时间专注看文章。过去 10 年一直都在坚持每天的技术文章阅读，有段时间也专门写周刊分享给组里的成员，以后有精力的话会整理在这里。 <a href="https://lightcss.com/reading-list-1/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-jetpack-markdown"><p>近期受疫情影响一直在远程办公，部分项目的推进节奏有所放缓，自己也有了更多时间专注看文章。过去 10 年每天都在坚持阅读技术文章，有段时间还专门写周刊分享给组里的成员，以后有精力的话会发到这里。</p>
<ul>
<li><a href="https://whoisryosuke.com/blog/2020/utility-props-for-web-components/">Utility Props for Web Components</a></li>
<li><a href="https://github.com/mateusortiz/webcomponents-the-right-way">https://github.com/mateusortiz/webcomponents-the-right-way</a></li>
</ul>
<blockquote>
<p>最近在用 Web Components 开发组件，有两个项目值得推荐给大家长期关注：<a href="https://stenciljs.com/">Stencil</a> 和 <a href="https://svelte.dev/">Svelte</a>。前者是面向 Web Components 的加工工具（Web Component Factory），后者是我关注很久的一个前端框架，小巧精悍，最近有变火&#x1f525;的趋势。</p>
</blockquote>
<ul>
<li><a href="https://levelup.gitconnected.com/understand-rxjs-subjects-97b43f9d32ba">Understand RxJS Subjects</a></li>
<li><a href="https://evertpot.com/visited-links/">Use a:visited in your CSS stylesheet</a></li>
<li><a href="https://www.smashingmagazine.com/2020/03/css4-pros-cons-discussion/">Why Are We Talking About CSS4?</a></li>
<li><a href="https://levelup.gitconnected.com/stop-writing-unsafe-javascript-functional-programming-for-javascript-developers-9c5f19ab9e4">Stop Writing Unsafe JavaScript — Functional Programming for JavaScript Developers</a></li>
<li><a href="https://transform.tools/">Transform</a>：常见数据类型转换器</li>
<li><a href="https://maxbittker.github.io/broider/">broider</a>：一个 <code>border-image</code> 生成器，但是并没有什么用。</li>
<li><a href="http://tholman.com/mosquito-js/">Mosquito.js</a>：声音稍微调大点，原生蚊子。</li>
<li><a href="https://zh.javascript.info/">现代 JavaScript 教程</a>：感觉是目前最好的中文教程，适合新手学习。</li>
</ul>
<p>-- EOF --</p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/reading-list-1/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">720</post-id>	</item>
		<item>
		<title>在 MacOS 下捕获模拟器中发出的网络请求</title>
		<link>https://lightcss.com/network-traffic-capture-simulator/</link>
					<comments>https://lightcss.com/network-traffic-capture-simulator/#comments</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sun, 21 May 2017 14:46:00 +0000</pubDate>
				<category><![CDATA[前端开发]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[ReactNative]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[移动开发]]></category>
		<guid isPermaLink="false">http://lightcss.com/?p=494</guid>

					<description><![CDATA[最近在做一个 React Native 项目遇到了一个小问题：安装 react-native-cookieman &#8230; <a href="https://lightcss.com/network-traffic-capture-simulator/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>最近在做一个 React Native 项目遇到了一个小问题：安装 react-native-cookiemanager 后，如何测试 cookie 是否设置成功并随请求发送，同时不影响 React Native 本地编译服务的连接（即不影响远程 JS Debug、热刷新等功能）。</p>
<p><span id="more-494"></span></p>
<h4>使用 Charles 全局代理捕获网络请求</h4>
<p>单纯的使用 Charles 抓包，需要给模拟器或测试机指定代理到本机 IP 的 8888 端口。这样虽然可以捕获请求，但也导致热刷新无法连接本地开发服务器。之后我尝试使用 Charles 全局代理来抓包，结果发现依然不能捕获 Genymotion 里的请求。网上搜了一下，还是需要在模拟器系统里设置网络代理到 10.0.3.2:8888，这样一来就跟 Charles 本身代理无异了。</p>
<h4>使用 Wireshark 捕获网络请求</h4>
<p><img data-recalc-dims="1" fetchpriority="high" decoding="async" class="alignnone wp-image-497 size-large" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-0-1024x444.jpg?resize=640%2C278" alt="" width="640" height="278" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-0.jpg?resize=1024%2C444&amp;ssl=1 1024w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-0.jpg?resize=600%2C260&amp;ssl=1 600w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-0.jpg?resize=768%2C333&amp;ssl=1 768w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-0.jpg?w=1280&amp;ssl=1 1280w" sizes="(max-width: 640px) 100vw, 640px" /></p>
<p>后来同事建议直接用 Wireshark，虽然有点大炮打蚊子但还是轻松地解决了我的需求。</p>
<p><img data-recalc-dims="1" decoding="async" class="alignnone wp-image-495 size-full" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-1-e1495376681272.jpg?resize=640%2C293" alt="" width="640" height="293" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-1-e1495376681272.jpg?w=850&amp;ssl=1 850w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-1-e1495376681272.jpg?resize=600%2C275&amp;ssl=1 600w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-1-e1495376681272.jpg?resize=768%2C351&amp;ssl=1 768w" sizes="(max-width: 640px) 100vw, 640px" /></p>
<p>在 Wireshark 里设置想抓取的域名/IP 以及接口就可以了。</p>
<p><img data-recalc-dims="1" decoding="async" class="alignnone size-full wp-image-496" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-2.jpg?resize=409%2C366" alt="" width="409" height="366"></p>
<p>捕获到请求后，右键选择「追踪流」-「HTTP 流」。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-full wp-image-498" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-3.jpg?resize=640%2C775" alt="" width="640" height="775" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-3.jpg?w=678&amp;ssl=1 678w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-3.jpg?resize=495%2C600&amp;ssl=1 495w" sizes="auto, (max-width: 640px) 100vw, 640px" /></p>
<p>然后就会弹一个新窗口展示了请求的完整信息。此时已经可以看到请求时的 cookie 等信息了。</p>
<p>这样我就可以一边开发一边测试了，而不需要频繁切代理。需要注意的是 Wireshark 如果在配置不佳的机器（如单位的 iMac）上使用，如果开启捕获后不关掉，时间久了可能会卡死。所以抓完包即时关掉，随用随开。</p>
<h4>使用 Debookee 捕获网络请求</h4>
<p>同样是同事推荐的应用，之前没用过。这个是付费的，但是界面简洁很多。打开后开启捕获，然后左边直接切换到 HTTP 请求就行了。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-large wp-image-500" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-4-1024x643.jpg?resize=640%2C402" alt="" width="640" height="402" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-4.jpg?resize=1024%2C643&amp;ssl=1 1024w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-4.jpg?resize=600%2C377&amp;ssl=1 600w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-4.jpg?resize=768%2C482&amp;ssl=1 768w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-4.jpg?w=1280&amp;ssl=1 1280w" sizes="auto, (max-width: 640px) 100vw, 640px" /></p>
<p>每条请求点箭头展开就能查看详细信息，非常方便。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-large wp-image-499" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-5-1024x295.jpg?resize=640%2C184" alt="" width="640" height="184" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-5.jpg?w=1024&amp;ssl=1 1024w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-5.jpg?resize=600%2C173&amp;ssl=1 600w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/genymotion-network-capture-5.jpg?resize=768%2C221&amp;ssl=1 768w" sizes="auto, (max-width: 640px) 100vw, 640px" /></p>
<p>遗憾的是免费版功能有限制，开一会儿捕获的数据就「打码」展示了，此时重开一下就好。舍不得花 $29.90 买，所以忍了。</p>
<h4>相关下载</h4>
<ul>
<li>Charles（$50）：<a href="https://www.charlesproxy.com/" target="_blank" rel="noopener noreferrer">官网</a></li>
<li>Wireshark（免费）：<a href="https://www.wireshark.org/" target="_blank" rel="noopener noreferrer">官网</a></li>
<li>Deebookee（$29.90起）：<a href="https://debookee.com/" target="_blank" rel="noopener noreferrer">官网</a></li>
</ul>
<p>-- EOF --</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/network-traffic-capture-simulator/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">494</post-id>	</item>
		<item>
		<title>[译]ES6 中你应该知道的 Numbers 用法</title>
		<link>https://lightcss.com/what-you-should-know-about-numbers-in-es6-javascript/</link>
					<comments>https://lightcss.com/what-you-should-know-about-numbers-in-es6-javascript/#respond</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sat, 13 May 2017 16:18:05 +0000</pubDate>
				<category><![CDATA[前端开发]]></category>
		<category><![CDATA[ES6]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[翻译]]></category>
		<guid isPermaLink="false">http://lightcss.com/?p=470</guid>

					<description><![CDATA[本文翻译自：What You Should Know About Numbers in ES6 Ja &#8230; <a href="https://lightcss.com/what-you-should-know-about-numbers-in-es6-javascript/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p><em>本文翻译自：<a href="https://hackernoon.com/what-you-should-know-about-numbers-in-es6-javascript-7370be6b3469" target="_blank" rel="noopener noreferrer">What You Should Know About Numbers in ES6 JavaScript</a></em></p>
<p>在 JavaScript 中，数据类型 <em>Number</em> 被应用在很多地方。自 ES6 起，<em>Number</em> 有了大量地改进来帮助开发者提升开发效率。下面是 ES6 为我们带来的几个新特性。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-full wp-image-479" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-0.jpg?resize=640%2C420" alt="" width="640" height="420" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-0.jpg?w=640&amp;ssl=1 640w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-0.jpg?resize=600%2C394&amp;ssl=1 600w" sizes="auto, (max-width: 640px) 100vw, 640px" /></p>
<p><span id="more-470"></span></p>
<h4>二进制与八进制直接量</h4>
<p>对新人来讲，开发者现在能够在 ES6 中使用前缀来表达不同的数字系统。</p>
<p>表达二进制数字使用 <strong>0b 前缀</strong>，使用 <strong>00 前缀</strong>表达八进制数字（译注：都是数字 0）。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-478 aligncenter" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-1.jpg?resize=279%2C143" alt="" width="279" height="143" /></p>
<h4>Number.isNaN</h4>
<p><code>Number.isNaN</code> 与它的<em>全局</em>函数不同。它不会在比较前通过 <code>Number(value)</code> 作数字类型转换。</p>
<p>只有数值<strong>确实是</strong> NaN 时 <code>Number.isNaN</code> 才会返回真。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-477 aligncenter" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-2.jpg?resize=198%2C152" alt="" width="198" height="152" /></p>
<p>蛋疼的是 <code>typeof NaN === 'number'</code>，所以 <code>typeof NaN === 'number'</code> 并不能精准地告诉你值是否是一个数字。它只告诉你该值属于数字，也包括了 NaN。</p>
<p>因此更精确的判断方式是：</p>
<pre class="prettyprint"><code class="js">typeof value === 'number' &amp;&amp; !Number.isNaN(value)</code></pre>
<p>当然，其它处理数字是否被错误描述的方式包括 <code>Number(x) === x</code> 将只在数字时返回 true。</p>
<h4>Number.isFinite</h4>
<p><code>Number.isFinite</code> 同样与全局的 <code>isFinite</code> 有些区别，<code>Number.isFinite</code> 不会在计算前通过 <code>Number(value)</code> 作数字类型转换。</p>
<p>例如，非数字在类型转换时会等于 0（<code>Number(null) === 0</code>）。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-476 aligncenter" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-3.jpg?resize=304%2C98" alt="" width="304" height="98" /></p>
<p>这种情况下 <code>Number.isFinite</code> 更高级一些。</p>
<h4>Number.isInteger</h4>
<p>这是 ES6 的新功能，它可以检测一个数字是否是整数。不需要用 <code>Number(value)</code> 作类型转换，非数字例如 null 会直接返回 false。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-475 aligncenter" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-4.jpg?resize=229%2C193" alt="" width="229" height="193" /></p>
<h4>Number.parseInt, Number.parseFloat</h4>
<p><code>Number.parseInt</code> 和 <code>Number.parseFloat</code> 跟他们的<em>全局</em>函数表现一毛一样。</p>
<h4>Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER</h4>
<p>它们表述了在 JavaScript 的实现里，可以安全使用的最大/最小数值。它由 IEEE 浮点限制（IEEE 754）在 2⁵³-1。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-474 aligncenter" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-5.jpg?resize=268%2C146" alt="" width="268" height="146" /></p>
<p>当然，最小安全整数是最大值的<em>负值</em>。要记住电脑在内存里是如何存储数字的。</p>
<h4>Number.isSafeInteger</h4>
<p><code>Number.isSafeInteger</code> 直接返回提供的值是否位于上面的最大/最小值之间。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-473 aligncenter" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-6.jpg?resize=272%2C239" alt="" width="272" height="239" /></p>
<h4>Number.EPSILON</h4>
<p>在 JavaScript 里，当浮点数在系统里不能被精确描述时会触发取整误差。例如，.1 加 .2 不等于 .3！</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-472 aligncenter" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-7.jpg?resize=227%2C57" alt="" width="227" height="57" /></p>
<p><code>Number.EPSILON</code> 提供了一个可接受的误差范围用来计算（译注：Number.EPSILON 属性表示数字 1 和在 JavaScript 里大于 1 的最小数值之间的差值，详见 <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON" target="_blank" rel="noopener noreferrer">MDN</a>）。所以可以用来检测计算误差是否处于可接受的范围，就像这样：</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="size-full wp-image-471 aligncenter" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-8.jpg?resize=640%2C47" alt="" width="640" height="47" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-8.jpg?w=674&amp;ssl=1 674w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/es6-numbers-8.jpg?resize=600%2C44&amp;ssl=1 600w" sizes="auto, (max-width: 640px) 100vw, 640px" /></p>
<hr />
<p>在 ES6 中，Numbers 有了长足的进步，并且仍有不少进步的空间，像这样的增强也帮助 ES6 变的比以往的 JavaScript 版本更优秀。（卧槽，这就忽然写结束语了？好 TM 突然！）</p>
<p>-- EOF --</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/what-you-should-know-about-numbers-in-es6-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">470</post-id>	</item>
		<item>
		<title>调整 WebStorm/PhpStorm 的内存限制</title>
		<link>https://lightcss.com/increase-phpstorm-memory/</link>
					<comments>https://lightcss.com/increase-phpstorm-memory/#comments</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sun, 07 May 2017 15:27:40 +0000</pubDate>
				<category><![CDATA[软件技巧]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[PhpStorm]]></category>
		<category><![CDATA[WebStorm]]></category>
		<guid isPermaLink="false">http://lightcss.com/?p=466</guid>

					<description><![CDATA[在处理大型项目时，WebStorm/PhpStorm 经常会遇到内存不够用导致响应缓慢的情况，原因是默 &#8230; <a href="https://lightcss.com/increase-phpstorm-memory/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>在处理大型项目时，WebStorm/PhpStorm 经常会遇到内存不够用导致响应缓慢的情况，原因是默认的 JVM 配置限制了内存大小（MacOS 64 位版默认是 750M）。<br />
<span id="more-466"></span></p>
<p>过去调整限制很麻烦，要到应用目录里面改配置（<code>/Applications/PhpStorm.app/Contents/bin/phpstorm.vmoptions</code>），不知道什么版本起多了一个选项，可以快速在应用里进入设置：「Help」——「Edit Custom VM Options」。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-full wp-image-467" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/phpstorm-vmoptions.jpg?resize=413%2C425" alt="" width="413" height="425" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/phpstorm-vmoptions.jpg?w=413&amp;ssl=1 413w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/05/phpstorm-vmoptions.jpg?resize=50%2C50&amp;ssl=1 50w" sizes="auto, (max-width: 413px) 100vw, 413px" /></p>
<p>如果之前没有改过则会提示创建一个配置，然后在配置里调大 <code>-Xmx</code>（最大可占内存）参数后重启应用就可以了。</p>
<pre class="prettyprint"><code class="plain">-Xmx2048m</code></pre>
<p>具体的数值根据电脑配置而定，我分的 2G。提高此值大小会对 IDE 的响应速度有显著改善。另外这个修改对其它 Java 平台的 IDE 也有效，例如丑的一逼的 eclipse。</p>
<p>当然还有一些深入优化的参数，就不深入挖掘了，具体可看下面「相关链接」的第二条。一般情况下设置好内存限制、把没用的插件都禁用掉就可以带来很好的运行速度了。</p>
<h4>相关链接</h4>
<ul>
<li><a href="https://www.jetbrains.com/help/phpstorm/2017.1/tuning-phpstorm.html" rel="external">Tuning PhpStorm</a></li>
<li><a href="https://dzone.com/articles/the-one-and-only-reason-to-customize-intellij-idea" rel="external">The One and Only Reason to Customize IntelliJ IDEA Memory Settings</a></li>
</ul>
<p>-- EOF --</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/increase-phpstorm-memory/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">466</post-id>	</item>
		<item>
		<title>使用 Media Query 检测设备 Reduced Motion 设置</title>
		<link>https://lightcss.com/use-media-query-detect-reduced-motion/</link>
					<comments>https://lightcss.com/use-media-query-detect-reduced-motion/#comments</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sat, 29 Apr 2017 10:42:02 +0000</pubDate>
				<category><![CDATA[前端开发]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Media Query]]></category>
		<guid isPermaLink="false">http://lightcss.com/?p=462</guid>

					<description><![CDATA[最近在看《Smooth Scrolling and Accessibility1 》这篇文章时，发现在 Safa &#8230; <a href="https://lightcss.com/use-media-query-detect-reduced-motion/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>最近在看《Smooth Scrolling and Accessibility<sup><a id="ffn1" class="footnote" href="#fn1">1</a></sup> 》这篇文章时，发现在 Safari 10.1 中增加了一个好玩的访问性检测——Reduced Motion<sup><a id="ffn2" class="footnote" href="#fn2">2</a></sup>，因此可以通过特性检测区分并对一些配置较差或主动开启「减弱动态效果」的用户进行体验优化。</p>
<p><img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone wp-image-463 size-full" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/vertigo.jpg?resize=640%2C360" alt="" width="640" height="360" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/vertigo.jpg?w=800&amp;ssl=1 800w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/vertigo.jpg?resize=600%2C338&amp;ssl=1 600w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/vertigo.jpg?resize=768%2C432&amp;ssl=1 768w" sizes="auto, (max-width: 640px) 100vw, 640px" /></p>
<p><span id="more-462"></span></p>
<h3>开启「减弱动态效果」</h3>
<p>「减弱动态效果」设置无论在 MacOS 还是 iOS 里都隐藏的比较深：</p>
<ul>
<li>MacOS：进入「系统偏好设置」-「辅助功能」-「显示器」，开启「减弱动态效果」；<sup><a id="ffn3" class="footnote" href="#fn3">3</a></sup></li>
<li>iOS：进入「设置」-「通用」-「辅助功能」-「减弱动态效果」，开启选项。<sup><a id="ffn4" class="footnote" href="#fn4">4</a></sup></li>
</ul>
<p>开启「减弱动态效果」可以有效地降低 MacOS/iOS 系统糟糕的<del datetime="2017-04-29T10:22:04+00:00">晕眩效果</del>性能开销，从而达到系统更流畅的功效。</p>
<h3>特性检测</h3>
<p>Reduced Motion 功能的检测关键词是 <code>prefers-reduced-motion</code>，使用 CSS Media Query 就可以针对开启「减弱动态效果」的用户进行页面性能优化：</p>
<pre class="prettyprint"><code class="css">@keyframes ambient {
  // Keyframes for an ambient animation that is purely decorative.
}
 
.background {
  animation: ambient 10s infinite alternate;
}
 
@media (prefers-reduced-motion) {
  // Disable the non-essential animations.
  .background {
     animation: none;
  }
}</code></pre>
<p>使用 JavaScript 则是使用 <code>matchMedia</code> 检测，还能监听改变事件：</p>
<pre class="prettyprint"><code class="js">var motionQuery = window.matchMedia('(prefers-reduced-motion)');
if (motionQuery.matches) {
    /* reduce motion */
}
motionQuery.addListener( handleReduceMotionChanged );
</code></pre>
<p>用 Safari 查看下面的演示，按照上面的切换方式来观察不同。</p>
<p><iframe loading="lazy" style="width: 100%;" title="Reduce Motion Media Query Example" src="//codepen.io/ericwbailey/embed/preview/PWJPrW/?height=265&amp;theme-id=dark&amp;default-tab=result&amp;embed-version=2" width="300" height="265" frameborder="no" scrolling="no" allowfullscreen="allowfullscreen">See the Pen <a href="http://codepen.io/ericwbailey/pen/PWJPrW/">Reduce Motion Media Query Example</a> by Eric Bailey (<a href="http://codepen.io/ericwbailey">@ericwbailey</a>) on <a href="http://codepen.io">CodePen</a>.</iframe></p>
<h3>使用场景</h3>
<p>因为这是 MacOS/iOS 独有的设置，所以目前也只有在 Safari 里可以一用。这个功能非常适合为低配置设备的用户以及追求性能的用户做体验优化，因为很多用户会开启「减弱动态效果」来在旧设备上提升系统流畅度。</p>
<p>比如我的博客背景有一个大的 Canvas，很多人反映说访问时风扇狂啸，那么就可以在检测到开启「减弱动态效果」时主动关闭一些无关紧要的动画从而提升用户的体验。</p>
<p>如果碰巧你用的不是 MacBook，那么你应该去买一个:-P</p>
<p>-- EOF --</p>
<ol id="footnotes">
<li id="fn1"><a title="Smooth Scrolling and Accessibility" href="https://css-tricks.com/smooth-scrolling-accessibility/">Smooth Scrolling and Accessibility</a> <a href="#ffn1">&#x21a9;︎</a></li>
<li id="fn2"><a title="Reduced Motion Media Query" href="https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Articles/Safari_10_1.html#//apple_ref/doc/uid/TP40014305-CH12-DontLinkElementID_61">Reduced Motion Media Query</a> <a href="#ffn2">&#x21a9;︎</a></li>
<li id="fn3"><a title="macOS Sierra: Reduce screen motion" href="https://support.apple.com/kb/PH25204">macOS Sierra: Reduce screen motion</a> <a href="#ffn3">&#x21a9;︎</a></li>
<li id="fn4"><a title="Reduce screen motion on your iPhone, iPad, or iPod touch" href="https://support.apple.com/en-us/HT202655">Reduce screen motion on your iPhone, iPad, or iPod touch</a> <a href="#ffn4">&#x21a9;︎</a></li>
</ol>
<hr />
<p>Update 2019.04.25：自 Chrome 74 起，也<a href="https://developers.google.com/web/updates/2019/04/nic74#prefers-reduced-motion">支持该特性检测</a>了。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/use-media-query-detect-reduced-motion/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">462</post-id>	</item>
		<item>
		<title>解决 VMware Fusion 中虚拟机启动时报「Could not open /dev/vmmon」的问题</title>
		<link>https://lightcss.com/fix-vmware-fusion-could-not-open-dev-vmmon/</link>
					<comments>https://lightcss.com/fix-vmware-fusion-could-not-open-dev-vmmon/#respond</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sun, 23 Apr 2017 13:38:50 +0000</pubDate>
				<category><![CDATA[软件技巧]]></category>
		<category><![CDATA[VirtualBox]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[虚拟机]]></category>
		<guid isPermaLink="false">http://lightcss.com/?p=425</guid>

					<description><![CDATA[最近在做 RN 开发，安装了 Genymotion 模拟器。之后发现开 VMware Fusi &#8230; <a href="https://lightcss.com/fix-vmware-fusion-could-not-open-dev-vmmon/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>最近在做 RN 开发，安装了 Genymotion 模拟器。之后发现开 VMware Fusion 虚拟机调试旧 IE 时，会在启动时报「Could not open /dev/vmmon」的错误导致无法启动。<br />
<span id="more-425"></span></p>
<blockquote><p>Could not open /dev/vmmon<br />
Failed to initialize monitor device</p></blockquote>
<p>如果用 <code>sudo kextutil /System/Library/Extensions/vmmon.kext</code> 启动则会报错：</p>
<blockquote><p>Kext com.vmware.kext.vmx86 failed to load (0xdc008017).<br />
Failed to load kext com.vmware.kext.vmx86 (error 0xdc008017).</p></blockquote>
<p>在网上搜了一下，原因是 VMware Fusion 跟 VirtualBox（Genymotion 和 Docker for Mac 都会依赖的免费虚拟机应用）共存时，如果装了太多虚拟机或虚拟设备，会导致双方共同占用一项共享的系统资源（major device number），导致它被 VirtualBox 占满时 VMware Fusion 中的虚拟机无法启动。解决的方法很暴利，卸载 VirtualBox 就行了。</p>
<p>卸载完可以使用指令 <code>sudo kextutil /System/Library/Extensions/vmmon.kext</code> 启动，然后通过 <code>kextstat | grep vmx</code> 就可以看到已经启动成功。</p>
<h4>相关文章</h4>
<ul>
<li><a href="https://communities.vmware.com/thread/469762">https://communities.vmware.com/thread/469762</a></li>
<li><a href="https://communities.vmware.com/thread/456399">https://communities.vmware.com/thread/456399</a></li>
<li><a href="https://communities.vmware.com/thread/430034">https://communities.vmware.com/thread/430034</a></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/fix-vmware-fusion-could-not-open-dev-vmmon/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">425</post-id>	</item>
		<item>
		<title>使用 BEM 的几个注意事项</title>
		<link>https://lightcss.com/common-mistakes-of-bem-naming/</link>
					<comments>https://lightcss.com/common-mistakes-of-bem-naming/#respond</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sun, 16 Apr 2017 02:45:13 +0000</pubDate>
				<category><![CDATA[前端开发]]></category>
		<category><![CDATA[BEM]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[命名规范]]></category>
		<guid isPermaLink="false">http://lightcss.com/?p=456</guid>

					<description><![CDATA[最近在做新的博客主题，又恰巧在整理 HTML 中为元素命名方面的心得，就借机重温了一 &#8230; <a href="https://lightcss.com/common-mistakes-of-bem-naming/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>最近在做新的博客主题，又恰巧在整理 HTML 中为元素命名方面的心得，就借机重温了一下 BEM 文档。或许是太久没看官方文档，我发现 BEM 如今已经延伸到了 Web 开发实践的范畴，而不再是一个单纯的命名规范。好坏不谈，总结一下注意事项。</p>
<p><span id="more-456"></span><br />
<img data-recalc-dims="1" loading="lazy" decoding="async" class="alignnone size-medium wp-image-457" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/bem-block-600x298.png?resize=400%2C199" alt="" width="400" height="199" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/bem-block.png?resize=600%2C298&amp;ssl=1 600w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/bem-block.png?resize=768%2C381&amp;ssl=1 768w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/bem-block.png?w=999&amp;ssl=1 999w" sizes="auto, (max-width: 400px) 100vw, 400px" /></p>
<h3>命名规则</h3>
<p>过去的 BEM 语法冗长丑陋，期间也经历了几种方式（现在依然共存）：</p>
<pre class="prettyprint"><code class="css">/* 旧：破折号式 */
.block-name {}
.block-name__element-name {}
.block-name__element-name--modifier-name {}

/* 旧：驼峰式 */
.blockName {}
.blockName--modifierName {}
.blockName__elementName--modifierName {}
</code></pre>
<p>而现在的命名规则主要是对修饰符的连接符做了调整——破折号改为单下划线链接：</p>
<pre class="prettyprint"><code class="css">.block-name {}
.block-name__element-name_modifier-name {}
</code></pre>
<h3>如何使用块与元素</h3>
<ul>
<li>如果一个区域可以复用且不依赖其它组件，则可作为一个块（Block）。</li>
<li>如果一个区域不能拿到外部单独使用，那么就应该作为一个元素（Element）。</li>
<li>元素不能单独使用，只能作为块的一部分使用。元素不能包含元素，因为这样做会妨碍块内部元素位置的层级调整。
<pre class="prettyprint"><code class="css">&lt;!-- 错误范例 --&gt;
&lt;form class="search-form"&gt;
    &lt;div class="search-form__content"&gt;
        &lt;!-- 应该使用： search-form__input 或 search-form__content-input --&gt;
        &lt;input class="search-form__content__input"&gt;
        &lt;!-- 应该使用：search-form__button 或 search-form__content-button --&gt;
        &lt;button class="search-form__content__button"&gt;搜索&lt;/button&gt;
    &lt;/div&gt;
&lt;/form&gt;</code></pre>
</li>
<li>如果一个元素可以继续分解，则可使用「元素 + 块」混合的方式另起一个空间，下面会单独介绍。</li>
</ul>
<h3>修饰符的改进</h3>
<p>修饰符（Modifier）用来修饰块或元素的外表、状态或行为。修饰符不能单独使用，而且必须绑定在对应的块或元素上，不能混搭。</p>
<pre class="prettyprint"><code class="css">&lt;button class="button button_active"&gt;...&lt;/button&gt;</code></pre>
<p>现在除了布尔值修饰符，还可以使用 Key-value 形式。</p>
<ul>
<li>一般来讲，如果修饰符的值可有可无（disabled、readonly 等，有则是 true，没有则是 false），那么可以省略修饰符的值。</li>
<li>如果修饰符的值可以有多种状态，则使用 Key-value 形式。</li>
</ul>
<p>另外，因为修饰符的连接符从 <code>--</code> 变成了 <code>_</code>，所以并不像过去那么丑陋了。</p>
<pre class="prettyprint"><code class="css">/* 使用布尔值表示状态（禁用、可见、聚焦等） */
.btn_disabled {}
.header__search-form_focused {}
 /* 使用 Key-value 表示选项（尺寸、主题、类型等） */
.btn_size_s {}
.search-form_theme_dark {}
.menu__item_type_text {}
</code></pre>
<p>为什么修饰符一定要包含块名或元素名？</p>
<ul>
<li>每一个块都会建立独立的命名空间，可以有效的减少命名冲突；</li>
<li>显式说明修饰符所对应的块或元素，防止混淆；</li>
<li>代码搜索更加准确方便；</li>
<li>不包含块名或元素名，使用修饰符就必须使用组合选择器（<code>.btn.disabled</code>），这会增加样式权重使其难以覆盖。</li>
</ul>
<h3>使用混合拆分样式</h3>
<p>在 BEM 中，位置和布局样式通过父级块来进行设置。这就需要通过混合（Mix）组合块与元素，组合多个实体（块、元素、修饰符都被称作 BEM 实体）的表现与样式，同时不耦合代码。</p>
<pre class="prettyprint"><code class="css">&lt;!-- header 块 --&gt;
&lt;div class="header"&gt;
    &lt;!-- `search-form` 块混合 header 块的 `search-form` 元素 --&gt;
    &lt;div class="search-form header__search-form"&gt;&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>上面的例子通过混合的方式把位置样式从块中剥离，然后就可以在 <code>.header__search-form {}</code> 中设置表单的位置或浮动等样式，从而保持了 <code>search-form </code> 块的样式独立，对其完整样式代码进行了解耦。这并不陌生——在传统命名方式中，我们经常通过嵌套的方式（<code>.header .search-form</code>）对局部样式进行调整。但这样做会改变选择器的权重。在 BEM 的思想中，保持选择器扁平和低权重是一个准则。</p>
<p>因此，在使用 BEM 时需要格外注意遵循它的工作方式：</p>
<ul>
<li>不在块里设置位置、布局相关的样式，只设置基本样式；</li>
<li>通过混合的方式，在作为父级块的元素时设置布局样式；</li>
<li>适时拆分元素为独立的块，解耦样式并形成新的命名空间。</li>
</ul>
<h3>避免组合使用标签与类选择器</h3>
<p>在 CSS 中使用 tag 一直不是一个好的实践，但在有些时候却难以避免。唯一需要注意的是 <code>a.btn</code> 是无法被 <code>.btn_active</code> 覆盖的。因此组合使用标签与类选择器时要格外注意。当然，最好还是避免使用。</p>
<h3>适时使用嵌套选择器</h3>
<p>很多人说 BEM 是「禁止嵌套」的，这不完全准确。BEM 只是建议尽量保持嵌套层级<strong>越低越好</strong>。因为 CSS 的权重问题很多人处理不好，最终恶果就是不停的嵌套和为了增加权重而进行的无意义嵌套和 <code>!important</code>，这无疑增加了代码的耦合。</p>
<p>在你需要通过块状态对内部元素进行调整时，使用嵌套是很好的选择：</p>
<pre class="prettyprint"><code class="css">.btn_active .btn__text {}
.search-form_foucsed .search-form__input {}
.nav_theme_dark .nav__item {}
</code></pre>
<h3>块不一定是一个视觉上的区块</h3>
<p>在批量设置多个样式时，可以使用混合的方式建立一个纯样式抽象的「块」。此时块不对应页面上具体的一块区域，而是代表一组抽象样式。</p>
<pre class="prettyprint"><code class="css">&lt;article class="article text"&gt;&lt;/article&gt;
&lt;footer class="footer"&gt;
    &lt;div class="copyright text"&gt;&lt;/div&gt;
&lt;/footer&gt;
</code></pre>
<p>上面的例子把 <code>.text</code> 作为一个单独的文本样式块，用来声明特定的一种文字设置。</p>
<pre class="prettyprint"><code class="css">.text {
    font-family: Arial, sans-serif;
    font-size: 14px;
    color: #000;
}
</code></pre>
<p>同理，页面整体布局、栅格系统等，都可以作为单独的块来设置。</p>
<h3>开放/关闭原则</h3>
<p>任何 HTML 元素都应遵循向修饰符开放并拒绝改变的原则。换句话说，就是一个 HTML 元素应该便于通过修饰符对齐进行样式覆盖，但是不应该频繁对其本身进行修改，因为每次改动都将影响到所有元素。</p>
<h3>切换到 BEM 式 CSS</h3>
<ul>
<li>把 DOM 模型扔到一边，学习创造块。</li>
<li>不要使用 ID 选择器和标签选择器。</li>
<li>最小化选择器嵌套。</li>
<li>使用 class 命名约定来避免命名冲突，确保选择器名称具备自解释性。</li>
<li>用块、元素和修饰符的方式工作。</li>
<li>把可能会改变的 CSS 样式属性从块挪到修饰符里去。</li>
<li>使用混合。</li>
<li>把代码拆分成独立的部分从而更容易的使用单独的块。</li>
<li>重复使用块。</li>
</ul>
<hr />
<p><div id="attachment_458" style="width: 610px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" aria-describedby="caption-attachment-458" class="size-medium wp-image-458" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/bem-600x219.png?resize=600%2C219" alt="" width="600" height="219" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/bem.png?resize=600%2C219&amp;ssl=1 600w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/bem.png?resize=768%2C280&amp;ssl=1 768w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/bem.png?w=999&amp;ssl=1 999w" sizes="auto, (max-width: 600px) 100vw, 600px" /><p id="caption-attachment-458" class="wp-caption-text"><a href="https://en.bem.info/methodology/key-concepts/" target="_blank" rel="noopener">图片来源</a></p></div></p>
<h3>总结</h3>
<p>使用 BEM 的好处有很多：</p>
<ul>
<li>自解释性很强，看到即看懂。</li>
<li>强制 「块--元素_修饰符」结构，命名重复可能性大大降低，有效地防止了样式污染问题。</li>
<li>抽象核心样式，通过修饰符的方式减少代码复制。</li>
<li>提供良好的扩展性。</li>
</ul>
<p>而且现在 BEM 除了针对 CSS 的方案，在 JavaScript、文件解构上也有了充分设计。按照官方的姿态，BEM 已经不应再作为 SMACSS 或 OOCSS 的类比，而是接近 Web Components 的产品，同时提供了完整的针对项目的构造方案。</p>
<p>我个人还是更喜欢把它当做一个单纯的 CSS 命名方案来看待，因为在组件化开发的方面，现在有很多更好的方案可供选择。另外 BEM 也不是万能灵药，它虽然解决了命名冲突、权重混乱等问题，但在模块组织上并不是特别清晰，借鉴一些 SMACSS 中的思想会让你的项目更加清晰有条理。</p>
<p>光说不练假把式，在接下来的新主题中就会用 BEM + SMACSS 来操练一番。</p>
<p>-- EOF --</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/common-mistakes-of-bem-naming/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">456</post-id>	</item>
		<item>
		<title>GTD 对个人效率的提高和「7个习惯」学后感</title>
		<link>https://lightcss.com/gtd-personal-productivity-and-7-habits/</link>
					<comments>https://lightcss.com/gtd-personal-productivity-and-7-habits/#respond</comments>
		
		<dc:creator><![CDATA[Sivan]]></dc:creator>
		<pubDate>Sun, 09 Apr 2017 14:41:19 +0000</pubDate>
				<category><![CDATA[不想分类]]></category>
		<category><![CDATA[GTD]]></category>
		<category><![CDATA[效率]]></category>
		<category><![CDATA[管理]]></category>
		<guid isPermaLink="false">http://lightcss.com/?p=449</guid>

					<description><![CDATA[刚刚忙完了紧张的工作周期，紧接着就在周末补充了一下养分，学习了「7 个习 &#8230; <a href="https://lightcss.com/gtd-personal-productivity-and-7-habits/">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>刚刚忙完了紧张的工作周期，紧接着就在周末补充了一下养分，学习了「7 个习惯」。原本分享的内容刚写了一半，干脆停下来趁头脑清醒结合之前学习的个人效率提高方法总结一下感受。</p>
<p><span id="more-449"></span></p>
<p><div id="attachment_450" style="width: 410px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" aria-describedby="caption-attachment-450" class="size-full wp-image-450" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/productivity.jpg?resize=400%2C398" alt="" width="400" height="398" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/productivity.jpg?w=600&amp;ssl=1 600w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/productivity.jpg?resize=150%2C150&amp;ssl=1 150w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/productivity.jpg?resize=50%2C50&amp;ssl=1 50w" sizes="auto, (max-width: 400px) 100vw, 400px" /><p id="caption-attachment-450" class="wp-caption-text"><a href="https://business.tutsplus.com/tutorials/what-is-productivity--cms-25894" target="_blank" rel="noopener">图片来源</a></p></div></p>
<p>我在大概 4 年前开始关注个人效率提升相关的内容，当时我刚离开广州申请了 SOHO 的机会。虽然工作内容没有变化，但在家工作无论是时间还是精力上自己都有更强的把控，因此有一个契机可以践行所谓的「GTD」、「番茄工作法」理论。直到今日我还在使用 GTD 理论替代我的大脑进行任务规划与跟踪处理。</p>
<h3>Getting Things Done</h3>
<p>GTD 的核心理论是清空大脑，把所有个人事物的处理安排都转移到工具中去，从而让头脑专注于解决要事而不存杂念。</p>
<p>因此，使用 GTD 可以最大程度地把大脑从「任务管理助手」的工作中解放出来。在 GTD 理论中有一个经典的两分钟原则：如果一件事能在 2 分钟内完成，就立刻去做。否则就直接交给管理系统来暂存（丢给 GTD 理论中的「收件箱」）。在「7 个习惯」的学习中，我发现自己在第三象限（紧急不重要）耗费的时间明显比其他人少，这应该得益于这套理论。而通过 OmniFocus 的聚焦与透视功能，我可以清晰、准确的知道下一步应该干什么。</p>
<h4>GTD 过程</h4>
<p>具体落实到生活和工作中，就是遇到任务时、脑子里忽然蹦出想法时，根据两分钟原则去判断立刻完成还是丢到收件箱去，灵光乍现时不做深入分析而是快速捕捉想法。然后在固定时间把收件箱里的想法分配到各个分类、任务中去。同时结合定期的回顾、修正目标，把大任务拆成小任务，并逐一实现。</p>
<p>我经常按电脑的工作模式去分析人脑：一个人如果同时做多件事，精力和头脑往往应付不来，因为「内存」是有限的。即便你不同步处理，在脑海里记录一个顺序，依旧无法发挥最大功效，因为这些要事和琐事就像「计划任务」一样存在于系统中，你始终需要一个钟表去定时检查他们的状态。在学习和使用 GTD 理论的这几年里，头脑可以真正松弛、淡定的完成生活与工作中的事务。当然惰性会影响效果，但已然提升了很多。</p>
<h4>GTD 实践</h4>
<p>在具体的工作中，我通常在收集完任务后，每天 1 次对所有新任务进行整理和拆分然后切换到公司的透视下开始工作，这个透视下只展示所有工作项目的下一步任务（不是全部可用任务，也不含未来任务），这样待做列表项目并不多，不会造成额外的压迫感。每天下班前再对今天未完成的任务进行简单回顾和补充。</p>
<p>另外，工作期间不设提醒任务，避免不必要的中断。下班时间则可以放松处理打扰任务和统一解决相对紧急的非工作任务。</p>
<h4>其它理论</h4>
<p>另外值得一提的是「番茄工作法」，它算是一种更具体地执行方式。我不谈结果，但就像达芬奇睡眠一样，长期的坚持或许能带来效率和时间上的优化，可它在实际工作中实在难以落实。我在家 SOHO 的那段时间里曾坚持使用，但随着换了公司也不了了之。</p>
<h3>「7 个习惯」</h3>
<p>如果说 GTD 是面向任务和个体，专注于完成和克服拖延的方法，那么「7 个习惯」则是个人素质提高的解决方案。它不光在意品性，还注重对待他人技巧。所以更适合职场。</p>
<h4>主动积极</h4>
<p>习惯一是关于个人责任和态度。主动积极的核心是「我」。万事都以我的意愿为出发点深度思考，不埋怨或直接反射外在的因素（三思而行，避免不过脑子），相信积极的作用，同时主动创造先决条件（使用积极的语言）。</p>
<p>关于这个习惯最让我有新鲜感的是影响圈的内容。不为关注圈消耗情绪，精力集中在影响圈。结合到自身工作，技术与行业发展不是自身可定的，仅保持关注，不掺杂情绪（因为并没有什么卵用）。主动积极的态度是专注自己能影响到的（个人技能提高与项目质量），并不断向外扩散自己的边界圈，影响跳起来就能够得着的果子。</p>
<h4>以终为始</h4>
<p>想法做事有目标和愿景，比如先挣它一个亿。感谢前面说的 GTD，它让我 check 的每一个勾勾都有意义。并且我知道它们的重要性。以终为始更宏大的意义就是定义长远的人生目标。抱歉，程序猿猝死的太多，这个问题我不敢多想。</p>
<h4>要事第一</h4>
<p>四象限图表可以很好的分析个人的工作效率，但更多的是分析和比较结果，适合定期检查。再次感谢前面说的 GTD，它带我实战。</p>
<p><div id="attachment_452" style="width: 446px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" aria-describedby="caption-attachment-452" class="size-full wp-image-452" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/time-quadrants.png?resize=436%2C408" alt="四象限图" width="436" height="408" /><p id="caption-attachment-452" class="wp-caption-text">四象限图 <a href="https://czarto.com/2012/04/24/four-quadrants-of-time/" target="_blank" rel="noopener">via</a></p></div></p>
<h4>双赢思维</h4>
<p>情感账户与利弊分析，职场「套路」第一弹。在多人协作中最重要的就是 1+1 能否 &gt;2 的问题，双赢思维是寻找共同利益的技能。实际的工作中，不可能永远双赢，保持主动积极的心态，创造双赢的机会。写博客、做分享，都是双赢思维，因为知识共享带来的是共同提升。</p>
<h4>知彼解己</h4>
<p>运用同理心理解别人的真实诉求。职场「套路」第二弹。了解他人，获得他人的理解。知彼解己无论在工作还是生活中，都是提高沟通效果的技能。</p>
<h4>统合综效</h4>
<p>珍视差异，寻求第三方案。双赢思维和知彼解己都是统和综效的先决条件，它们组成完整的团体任务流程。很多时候，集体讨论的方案会远优于个人方案，尤其是差异性集体的力量，更能碰撞出火花。因此，要勇于探索陌生的区域，勤于总结差异的价值。</p>
<h4>不断更新</h4>
<p>一个关于<strong>每日</strong>自我更新的习惯。就像 GTD 每日整理任务、每周回顾任务一样，不断更新是辅助自我克服拖延的习惯。坚持的力量需要时间来检查结果。习惯七从身体、心智、情感和心灵四方面持续锻炼，并且以天为单位进行更新，<strong>利用成功感去保持积极性</strong>。同时，习惯七建议找朋友一起计划，相互督促。跑步、健身、「GitHub 马拉松」等，无一不推荐这样的方式。</p>
<p><div id="attachment_453" style="width: 609px" class="wp-caption alignnone"><img data-recalc-dims="1" loading="lazy" decoding="async" aria-describedby="caption-attachment-453" class="size-full wp-image-453" src="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/7habits.png?resize=599%2C640" alt="七个习惯模型" width="599" height="640" srcset="https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/7habits.png?w=599&amp;ssl=1 599w, https://i0.wp.com/lightcss.com/wp-content/uploads/2017/04/7habits.png?resize=562%2C600&amp;ssl=1 562w" sizes="auto, (max-width: 599px) 100vw, 599px" /><p id="caption-attachment-453" class="wp-caption-text"><a href="http://www.jianshu.com/p/614df9a7a582" target="_blank" rel="noopener">图片来源</a></p></div></p>
<p>总体来讲，「7 个习惯」的核心是通过培养品性使人从依赖到独立，再通过技巧使人从独立到互赖的持续成熟地模式。</p>
<h3>GTD 与「7 个习惯」的结合</h3>
<p>随着后者的学习，我逐渐发现像 GTD 这样的理论集中在「事」，是一个规划和解决的工具。而「7 个习惯」则是在更宏观的角度，改善人的处事态度，提高生活的满足感。</p>
<p>具体在实践上，在 OmniFocus 中，主要视图是树状排列大脑想到过的所有可做的事，通过透视或下一步任务去筛选执行的顺序。最主要的是帮你把大小任务啃掉。而它最缺乏的就是中、长期的对已完成任务的分析和回溯。在习惯「要事第一」和「不断更新」中，则以天为单位，更好的观察到自身的进步。而 GTD 理论中虽然可以建立常态的重复任务，但是并不分析结果：只要任务完成，GTD 在这件任务上的使命就结束。另外，无论是 OmniFocus 还是 Things，在日历视图（宏观浏览周、月概况）均不方便，更多是为了进行任务预测，对任务耗时、精力分配没有很好的展示，在排期时或许会出现不合理的情况。</p>
<p>因此，「7 个习惯」除了主动积极、双赢思维、知彼解己、统合综效这几个思想习惯，其余的行为习惯都可以和 GTD 融合在一起。比如在日历中只进行二象限事务和情感、情绪事务记录，并且只用来概览和回溯。而各象限事务的具体实施和每日提高的提醒都交由 GTD 工作处理，使其更多的作为一个分配任务和通知的工具，保证计划顺利完成并敦促自己提升。同时指定定期任务，每周末找一个安静的时间对个人中长远目标做总结和思考。相信这样的结合可以最大程度实现习惯培养与工具的有效利用。</p>
<p>关于自我不断更新的四个方面，结合近两年生活和工作的变化，还有一些想总结的，等有空再说吧。写分享去了……</p>
<p>对了，最最后的，惰性才是阻碍效率提升的最大敌人。下定决心做的事，无论如何都要坚持下去。</p>
<p>-- EOF --</p>
]]></content:encoded>
					
					<wfw:commentRss>https://lightcss.com/gtd-personal-productivity-and-7-habits/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">449</post-id>	</item>
	</channel>
</rss>
