This file contains hidden or 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
OfflineModeRouteHelpers = Em.Mixin.create | |
robustlyLoadHasMany: (model, relationshipName) -> | |
new Em.RSVP.Promise (resolve, reject) => | |
model.get(relationshipName).then resolve, (error) => | |
internalModels = model.get("#{relationshipName}.content.canonicalState") | |
internalModels.forEach (internalModel) -> | |
internalModel._loadingPromise = null | |
internalModel.transitionTo('empty') | |
model.get(relationshipName).reload().then resolve, reject |
This file contains hidden or 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
/** | |
* `Ember.MergedArray` is an array that observes multiple other arrays (called source arrays) for changes and includes | |
* all items from all source arrays in an efficient way. | |
* | |
* Usage: | |
* | |
* ```javascript | |
* var obj = Ember.Object.create({ | |
* people: [ | |
* { |
This file contains hidden or 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
App.DynamicBoundTextField = Ember.TextField.extend | |
placeholderBinding: 'content.name' | |
# Update the remote property's value when the value of | |
# our text field changes | |
_setRemoteValue:(-> | |
val = @get('value') | |
@set("controller.data.#{@get('content.key')}", val) if val? | |
).observes('value') | |
This file contains hidden or 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
{"fields": [ | |
{ "name": "First Name", "key": "first_name" }, | |
{ "name": "Last Name", "key": "last_name" }, | |
{ "name": "Email", "key": "email" } | |
]} |
This file contains hidden or 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
before do | |
@target = ObjectUnderTest.new | |
end | |
it 'posts a notification named "Jump" with the height' do | |
@target.notifCenter = mock('postNotificationName:object:userInfo:') do | |
| name, object, userInfo | | |
name.should == 'Jump' | |
object.should == @target | |
userInfo.should == { 'height' => '10m' } | |
end |
This file contains hidden or 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
# Pure stub objects | |
my_stub = stub(:thing, :return => "dude, a thing!") | |
my_stub.thing # => "dude, a thing!" | |
# Mocking right on the object | |
my_object = "things are fun" | |
my_object.mock!(:fancy, :return => "ooo fancy!") | |
my_object.fancy # => "ooo fancy!" |
This file contains hidden or 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
describe Array do | |
it "calls the Rubyish count method on Rubyish arrays" do | |
count = [1,2,3,4,5,6].count { |i| i > 3 } | |
count.should == 3 | |
end | |
it "doesn't call the Rubyish count method on NSArray objects" do | |
nsarray = NSArray.arrayWithArray([1,2,3,4,5,6]) | |
nsarrayCount = nsarray.count { |i| i > 3 } | |
# The block above gets ignored and a warning is printed out in the console, so... |
This file contains hidden or 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
public Func<string, string> WithOneInput = Memoizer.Memoize( | |
(string x) => | |
{ | |
return String.Format("Hello, {0}", x); | |
} | |
); |
This file contains hidden or 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
public static Func<TSource1, TSource2, TReturn> Memoize<TSource1, TSource2, TReturn>(Func<TSource1, TSource2, TReturn> func) | |
{ | |
var cache = new Dictionary<string, TReturn>(); | |
return (s1, s2) => | |
{ | |
var key = s1.GetHashCode().ToString() + s2.GetHashCode().ToString(); | |
if (!cache.ContainsKey(key)) | |
{ | |
cache[key] = func(s1, s2); | |
} |
This file contains hidden or 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
public static Func<TSource, TReturn> Memoize<TSource, TReturn>(Func<TSource, TReturn> func) | |
{ | |
var cache = new Dictionary<TSource, TReturn>(); | |
return s => | |
{ | |
if (!cache.ContainsKey(s)) | |
{ | |
cache[s] = func(s); | |
} | |
return cache[s]; |
NewerOlder