expectDeprecation(() => { TestNamespace.toObject = EmberObject.extend({ valueBinding: Binding.from('TestNamespace.fromObject.value'), relativeBinding: Binding.from('localValue') }).create({ localValue: 'originalLocal' }); }, /`Ember\.Binding` is deprecated./);
run(function () { //Binding of output of MyApp.first object to input of MyApp.second object binding1 = Binding.from("first.output") .to("second.input").connect(MyApp) ; //Binding of output of MyApp.second object to input of MyApp.third object binding2 = Binding.from("second.output") .to("third.input").connect(MyApp) ; });
run(function () { TestNamespace.fromObject = EmberObject.create({ value: "originalValue" }); TestNamespace.toObject = EmberObject.createWithMixins({ valueBinding: Binding.from('TestNamespace.fromObject.value'), localValue: "originalLocal", relativeBinding: Binding.from('localValue') }); });
run(function () { TestNamespace.fromObject = EmberObject.create({ value: 'originalValue' }); TestNamespace.toObject = EmberObject.extend({ valueBinding: Binding.from('TestNamespace.fromObject.value'), relativeBinding: Binding.from('localValue') }).create({ localValue: 'originalLocal' }); });
testBoth('Calling connect more than once', function(get, set) { var b = { bar: 'BAR' }; var a = { foo: 'FOO', b: b }; // b.bar -> a.foo var binding = new Binding('foo', 'b.bar'); performTest(binding, a, b, get, set, function () { binding.connect(a); binding.connect(a); }); });
test('should accept bindings as a string or an Ember.Binding', function() { var ViewWithBindings = EmberView.extend({ oneWayBindingTestBinding: Binding.oneWay('context.direction'), twoWayBindingTestBinding: Binding.from('context.direction'), stringBindingTestBinding: 'context.direction', template: compile( "one way: {{view.oneWayBindingTest}}, " + "two way: {{view.twoWayBindingTest}}, " + "string: {{view.stringBindingTest}}" ) }); view = EmberView.create({ viewWithBindingsClass: ViewWithBindings, context: EmberObject.create({ direction: "down" }), template: compile("{{view view.viewWithBindingsClass}}") }); runAppend(view); equal(trim(view.$().text()), "one way: down, two way: down, string: down"); });
EmberHandlebars.registerHelper('boogie', function(id, options) { options.hash = options.hash || {}; options.hashTypes = options.hashTypes || {}; options.hash.bindingTestBinding = Binding.oneWay('context.' + id); options.hash.stringTestBinding = id; var result; if (Ember.FEATURES.isEnabled('ember-htmlbars')) { result = htmlbarsViewHelper.helper(viewClass, options.hash, options, options); } else { result = handlebarsViewHelper.helper(this, viewClass, options); } return result; });
QUnit.test('should accept bindings as a string or an Ember.Binding', function() { var ViewWithBindings = EmberView.extend({ twoWayBindingTestBinding: Binding.from('context.direction'), stringBindingTestBinding: 'context.direction', template: compile( 'two way: {{view.twoWayBindingTest}}, ' + 'string: {{view.stringBindingTest}}' ) }); view = EmberView.create({ viewWithBindingsClass: ViewWithBindings, context: EmberObject.create({ direction: 'down' }), template: compile('{{view view.viewWithBindingsClass}}') }); runAppend(view); equal(trim(view.$().text()), 'two way: down, string: down'); });
testBoth('Bindings should be inherited', function(get, set) { var a = { foo: 'FOO', b: { bar: 'BAR' } }; var binding = new Binding('foo', 'b.bar'); var a2; run(function () { binding.connect(a); a2 = create(a); rewatch(a2); }); equal(get(a2, 'foo'), "BAR", "Should have synced binding on child"); equal(get(a, 'foo'), "BAR", "Should NOT have synced binding on parent"); run(function () { set(a2, 'b', { bar: 'BAZZ' }); }); equal(get(a2, 'foo'), "BAZZ", "Should have synced binding on child"); equal(get(a, 'foo'), "BAR", "Should NOT have synced binding on parent"); });
export function collectionHelper(params, hash, options, env) { var path = params[0]; Ember.deprecate("Using the {{collection}} helper without specifying a class has been" + " deprecated as the {{each}} helper now supports the same functionality.", path !== 'collection'); Ember.assert("You cannot pass more than one argument to the collection helper", params.length <= 1); var data = env.data; var template = options.template; var inverse = options.inverse; var view = data.view; // This should be deterministic, and should probably come from a // parent view and not the controller. var controller = get(view, 'controller'); var container = (controller && controller.container ? controller.container : view.container); // If passed a path string, convert that into an object. // Otherwise, just default to the standard class. var collectionClass; if (path) { collectionClass = readViewFactory(path, container); Ember.assert(fmt("%@ #collection: Could not find collection class %@", [data.view, path]), !!collectionClass); } else { collectionClass = CollectionView; } var itemHash = {}; var match; // Extract item view class if provided else default to the standard class var collectionPrototype = collectionClass.proto(); var itemViewClass; if (hash.itemView) { itemViewClass = readViewFactory(hash.itemView, container); } else if (hash.itemViewClass) { itemViewClass = readViewFactory(hash.itemViewClass, container); } else { itemViewClass = collectionPrototype.itemViewClass; } if (typeof itemViewClass === 'string') { itemViewClass = container.lookupFactory('view:'+itemViewClass); } Ember.assert(fmt("%@ #collection: Could not find itemViewClass %@", [data.view, itemViewClass]), !!itemViewClass); delete hash.itemViewClass; delete hash.itemView; // Go through options passed to the {{collection}} helper and extract options // that configure item views instead of the collection itself. for (var prop in hash) { if (prop === 'itemController' || prop === 'itemClassBinding') { continue; } if (hash.hasOwnProperty(prop)) { match = prop.match(/^item(.)(.*)$/); if (match) { var childProp = match[1].toLowerCase() + match[2]; if (IS_BINDING.test(prop)) { itemHash[childProp] = view._getBindingForStream(hash[prop]); } else { itemHash[childProp] = hash[prop]; } delete hash[prop]; } } } if (template) { itemHash.template = template; delete options.template; } var emptyViewClass; if (inverse) { emptyViewClass = get(collectionPrototype, 'emptyViewClass'); emptyViewClass = emptyViewClass.extend({ template: inverse, tagName: itemHash.tagName }); } else if (hash.emptyViewClass) { emptyViewClass = readViewFactory(hash.emptyViewClass, container); } if (emptyViewClass) { hash.emptyView = emptyViewClass; } if (hash.keyword) { itemHash._contextBinding = Binding.oneWay('_parentView.context'); } else { itemHash._contextBinding = Binding.oneWay('content'); } var viewOptions = mergeViewBindings(this, {}, itemHash); if (hash.itemClassBinding) { var itemClassBindings = hash.itemClassBinding.split(' '); viewOptions.classNameBindings = map(itemClassBindings, function(classBinding) { return streamifyClassNameBinding(view, classBinding); }); } hash.itemViewClass = itemViewClass; hash._itemViewProps = viewOptions; options.helperName = options.helperName || 'collection'; return env.helpers.view.helperFunction.call(this, [collectionClass], hash, options, env); }
performTest(binding, a, b, get, set, function () { binding.connect(a); binding.connect(a); });
run(function () { binding.connect(a); a2 = create(a); rewatch(a2); });
/** Invoked by the run loop to actually destroy the object. This is scheduled for execution by the `destroy` method. @private @method _scheduledDestroy */ _scheduledDestroy() { if (this.isDestroyed) { return; } destroy(this); this.isDestroyed = true; }, bind(to, from) { if (!(from instanceof Binding)) { from = Binding.from(from); } from.to(to).connect(this); return from; }, /** Returns a string representation which attempts to provide more information than Javascript's `toString` typically does, in a generic way for all Ember objects. ```javascript App.Person = Em.Object.extend() person = App.Person.create() person.toString() //=> "<App.Person:ember1024>" ```
bind: function(to, from) { if (!(from instanceof Binding)) { from = Binding.from(from); } from.to(to).connect(this); return from; },