-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from hiddenswitch/apitweaks
Updates for next version
- Loading branch information
Showing
10 changed files
with
289 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Reflection; | ||
using JsonFx.Json; | ||
using Meteor.Extensions; | ||
|
||
namespace Meteor | ||
{ | ||
public class Cursor<TRecordType> | ||
where TRecordType : MongoDocument, new() | ||
{ | ||
|
||
public Collection<TRecordType> collection { | ||
get; | ||
protected set; | ||
} | ||
|
||
public Func<TRecordType, bool> selector { | ||
get; | ||
protected set; | ||
} | ||
|
||
public IEnumerable<string> ids { | ||
get; | ||
protected set; | ||
} | ||
|
||
public Cursor (Collection<TRecordType> collection, Func<TRecordType, bool> selector = null) | ||
{ | ||
this.collection = collection; | ||
this.selector = selector ?? SelectAll; | ||
} | ||
|
||
public Cursor (Collection<TRecordType> collection, string id) | ||
{ | ||
this.collection = collection; | ||
this.ids = new string[] { id }; | ||
} | ||
|
||
public Cursor (Collection<TRecordType> collection, IEnumerable<string> ids) | ||
{ | ||
this.collection = collection; | ||
this.ids = ids; | ||
} | ||
|
||
public Observe<TRecordType> Observe (Action<string,TRecordType> added = null, Action<string,TRecordType,IDictionary,string[]> changed = null, Action<string> removed = null) | ||
{ | ||
return new Observe<TRecordType> (collection: this.collection, added: added, changed: changed, removed: removed, selector: selector); | ||
} | ||
|
||
public IEnumerable<TRecordType> Fetch () | ||
{ | ||
if (ids == null) { | ||
foreach (var record in collection) { | ||
if (selector (record)) { | ||
yield return record; | ||
} | ||
} | ||
yield break; | ||
} | ||
|
||
foreach (var id in ids) { | ||
yield return collection [id]; | ||
} | ||
|
||
yield break; | ||
} | ||
|
||
private bool SelectAll (TRecordType record) | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.