Skip to content

Instantly share code, notes, and snippets.

@dcporter
dcporter / BestFitGridView
Created July 21, 2013 13:28
A quick-and-dirty BestFitGridView.
// A (quick and dirty) view which renders its content as a best-fit grid – that is, it shows all items,
// laid out as close to evenly as possible.
// Known issues:
// - doesn't update when content changes (wasn't part of my needs); easy observer fix
// - isn't a subclass of SC.CollectionView
// - someone with the maths could optimize the calculations
// - child views are never destroyed, only created and cached
BestFitGridView = SC.View.extend({
@dcporter
dcporter / timespan.js
Last active December 20, 2015 17:38
A proposed Timespan class for SproutCore to allow for easier comparison of time spans.
// ==========================================================================
// Project: SC.Timespan
// Copyright: @2013 My Company, Inc.
// ==========================================================================
/*globals SC */
/**
Standard error thrown when trying to create a timespan with dates in
different timezones.
@dcporter
dcporter / SC.AutonomousStore
Last active December 21, 2015 04:49
A gist for patching in autonomous nested stores (see https://github.com/sproutcore/sproutcore/pull/1000) while we work out how and when to integrate the ideas.
// SC.Store (for autonomous nested stores)
SC.Store.reopen({
chainAutonomousStore: function(attrs, newStoreClass) {
var newAttrs = attrs ? SC.clone( attrs ) : {};
var source = this._getDataSource();
newAttrs.dataSource = source;
return this.chain( newAttrs, newStoreClass );
}
});
@dcporter
dcporter / gist:6536417
Created September 12, 2013 12:15
Monkeypatches ManyArray with live status.
SC.ManyArray.reopen({
// Set up observers.
contentDidChange: function() {
var observedRecords = this._observedRecords;
if (!observedRecords) observedRecords = this._observedRecords = [];
var record, i, len;
// If any items in observedRecords are not in content, stop observing them.
len = observedRecords.length;
for (i = len - 1; i >= 0; i--) {
@dcporter
dcporter / FadingImageView.js
Created September 27, 2013 13:48
Fun With Transitions: ImageView that fades in on load.
/*
View Transitions, new in SC1.0, have made all kinds of effects drop-dead easy. Here's
an ImageView which will fade nicely in when the image loads.
*/
FadingImageView = SC.ImageView.extend({
isVisible: NO,
isVisibleBinding: SC.Binding.oneWay('.status').transform(function(status) { return status === SC.IMAGE_STATE_LOADED; }),
transitionShow: SC.View.FADE_IN,
transitionShowOptions: { duration: 0.25 },
@dcporter
dcporter / local_storage_data_source.js
Last active August 29, 2015 13:57
A data source for SproutCore which persists data to local storage instead of to a server.
// ==========================================================================
// Project: LocalStorageDataSource For SproutCore
// Copyright: 2014 Dave Porter & contributors
// License: Licensed under MIT license
// ==========================================================================
window.DCP = window.DCP || {};
/** @class
A data source which persists records to local storage.
@dcporter
dcporter / proxied_array_controller.js
Last active August 29, 2015 14:03
An ArrayController which exposes each content item wrapped in a proxy class.
// ==========================================================================
// Project: SC.ProxiedArrayController
// Copyright: ©2014 My Company, Inc.
// ==========================================================================
/*globals SC */
/** @class
This controller implements an experimental ArrayController pattern which wraps each item in a
controller object when retrieved.
// relies on Date.now() which has been supported everywhere modern for years.
// as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values
// if you want values similar to what you'd get with real perf.now, place this towards the head of the page
// but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed
(function(){
// prepare base perf object

Keybase proof

I hereby claim:

  • I am dcporter on github.
  • I am dcporter (https://keybase.io/dcporter) on keybase.
  • I have a public key whose fingerprint is BD85 FE84 FD28 4326 485C 3B8C AFB1 B485 1093 B29C

To claim this, I am signing this object:

// A public observable
export const myObservable = RxJS.something(
// ?
);
// A function I can call any time to emit `val` from `myObservable`
function secretFunction(val) {
// ?
}