mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
39 lines
1.3 KiB
HTML
39 lines
1.3 KiB
HTML
---
|
|
layout: docs
|
|
title: Matcher
|
|
edit_url: "https://github.com/nylas/N1/blob/master/src/flux/attributes/matcher.coffee"
|
|
---
|
|
|
|
<h2>Summary</h2>
|
|
|
|
<div class="markdown-from-sourecode">
|
|
<p><p>The Matcher class encapsulates a particular comparison clause on an <a href='attribute.html'>Attribute</a>.
|
|
Matchers can evaluate whether or not an object matches them, and also compose
|
|
SQL clauses for the DatabaseStore. Each matcher has a reference to a model
|
|
attribute, a comparator and a value.</p>
|
|
<pre><code class="lang-coffee">
|
|
<span class="hljs-preprocessor"># Retrieving Matchers</span>
|
|
|
|
isUnread = Thread.attributes.unread.equal(<span class="hljs-literal">true</span>)
|
|
|
|
hasLabel = Thread.attributes.lables.contains(<span class="hljs-string">'label-id-123'</span>)
|
|
|
|
<span class="hljs-preprocessor"># Using Matchers in Database Queries</span>
|
|
|
|
DatabaseStore.findAll(Thread).where(isUnread)...
|
|
|
|
<span class="hljs-preprocessor"># Using Matchers to test Models</span>
|
|
|
|
threadA = <span class="hljs-keyword">new</span> Thread(unread: <span class="hljs-literal">true</span>)
|
|
threadB = <span class="hljs-keyword">new</span> Thread(unread: <span class="hljs-literal">false</span>)
|
|
|
|
isUnread.evaluate(threadA)
|
|
<span class="hljs-preprocessor"># => true</span>
|
|
isUnread.evaluate(threadB)
|
|
<span class="hljs-preprocessor"># => false</span>
|
|
</code></pre>
|
|
</p>
|
|
</div>
|
|
|
|
<ul>
|
|
</ul>
|