Raphael JS Set ID for paper.set object - raphael

I want to provide an ID to a SET object. Any idea how to do it

In my knowledge there is only one way ....
extend the Raphael.st
Raphael.st.setID = function(id){
this.id = id;
}
var yourset = paper.set();
yourset.setID(id); //give the id you want
then try -> yourset.id;
I hope it works for you ....

Related

DynamoDB for .net: Table name in data model

I am using Dynamodb.net in my application.
I have the following code.
var creds = new BasicAWSCredentials(awsId, awsPassword);
var dynamoClient = new AmazonDynamoDBClient(creds,
awsDynamoDbRegion);
var context = new DynamoDBContext(dynamoClient);
List<ScanCondition> conditions = new List<ScanCondition>();
conditions.Add(new ScanCondition("Id", ScanOperator.Equal, myId));
var response = await context.ScanAsync<Data>(conditions).GetRemainingAsync();
return response;
My Data Model is as:
[DynamoDBTable("MyTable")]
public class Data
{
[DynamoDBHashKey]
public string Id{ get; set; }
public string Name { get; set; }
}
We are harcoding the table table name in our model "Data" as
[DynamoDBTable("MyTable")]
How can we not hardcode this. Is it possible to apply the table name in my actual code itself instead of giving in the model?
Thanks
Is OverrideTableName in DynamoDBOperationConfig what you are looking for ?
Description:
Property that indicates the table to save an object to overriding the
DynamoDBTable attribute declared for the type.
Example:
var x = await DbContext.LoadAsync<T>("hash", new DynamoDBOperationConfig {
OverrideTableName = "NewTableName",
IndexName = indexName
});
Also what you are looking for might be table prefix for every request of DbContext. It will append this prefix to every table. Useful if you want to isolate application specific tables like AppName-MyTable...
Example:
return new DynamoDBContextConfig
{
TableNamePrefix = "MyAppIdentifier",
ConsistentRead = false,
};
another option is to use different prefixes for the tables via
Amazon.DynamoDBv2.DataModel.DynamoDBContextConfig.TableNamePrefix
Property that directs DynamoDBContext to prefix all table names with a specific string. > If property is null or empty, no prefix is used and default table names are used.
https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/DynamoDBv2/TDynamoDBContextConfig.html
e.g.:
var credentials = new StoredProfileAWSCredentials("default");
var client = new AmazonDynamoDBClient(credentials, RegionEndpoint.USEast1);
var config = new DynamoDBContextConfig{
TableNamePrefix = "Test."
};
var ctx = new DynamoDBContext(client, config);
await ctx.SaveAsync(item);

How to get the changed object of an array when using ember oberver

I am using following code to get the details of the object whose property is changed.
getChangedObject:function(){
console.log('changed name is' , can i get the object here );
}.observes('model.#each.rollNo')
Thanks in advance.
Inside observer you cant get the exact object which caused observer to trigger, but you can try the below approach, like iterating array of model and watch for changed attributes alone.
getChangedObject: function() {
let model = this.get('model');
model.forEach(function(item, index) {
var changedAttributes = item.changedAttributes();
item.eachAttribute(function(item, meta) {
var temp = changedAttributes[item];
if(temp){
console.log(' old value ',temp[0],' new value ',temp[1]);
}
});
})
}.observes('model.#each.rollNo')

Caching and walking an ArrayController

I have a Phone model. I want to cache all phones on my application:
cachePhones : function () {
this.set('phones', this.Phone.find());
},
And get the countries for which I have available phones:
getCountries : function () {
var phones = this.get('phones.content');
var countries = new this.dataSet(), country;
console.log('phones=%o', phones.length);
for (var index = 0, length = phones.length; index < length; index++) {
country = phones[index].record.get('country');
console.log('Adding %o', country);
countries.add(country, true);
}
console.log('countries=%o', countries.keys());
return countries.keys();
},
(dataSet is just a set implementation in javascript)
I am not sure this is the right way to walk the ArrayController:
do I really need to access the content?
do I really need to access record?
This feels like hacking around my way in the ember internals. I have tried before this:
var phones = this.get('phones');
var countries = new this.dataSet(), country;
for (var index = 0, length = phones.length; index < length; index++) {
country = phones[index].country;
countries.add(country, true);
}
But it was not working at all. What is the canonical way of walking an ArrayController?
Have you tried something like this? Normally you should always be fine with using the functional methods Ember offers for its collections.
var phones = this.get('phones');
var countries = new this.dataSet(), country;
phones.forEach(function(phone, index){
country = phone.get("country");
countries.add(country, true);
});
Besides #mavilein correct answer one thing worth mentioning is that if you have a model like App.Phone then after you do App.Phone.find() and the records are fetched, your Store has already a cache which you can consult with App.Phone.all() this will not make another request but gives you the records available in the Store.
Hope it helps.

Automatic type casting of vanilla objects to Ember objects

I'm just diving in to Ember. I'm looking for a way to pass a plain array of vanilla objects into a collection/controller and have them type cast to the correct model.
Here's the simple collection view:
{{#collection id="prods" contentBinding="Vix.prodsController" tagName="ul"}}
{{content.title}}
{{/collection}}
Here's the model:
Vix.Prod = Ember.Object.extend({
id: null,
title: null
});
And the controller:
Vix.prodsController = Ember.ArrayController.create({
content: []
});
Then let's get some JSON-formatted data from the server. In this example I'll just hard-code it:
var prods = [{id:"yermom1", title:"yermom 1"}, {id:"yermom2", title:"yermom 2"}]
Vix.prodsController.set('content', prods);
So far so good. I get my simple list of li elements displaying the titles as I'd expect. But when I want to update the title of one of the objects, using:
Vix.prodsController.objectAt(0).set('title', 'new title')
It complains because the object has no set method-- it has not been properly cast to my Vix.Prod Ember Object.
Using this alternative:
Vix.prodsController.pushObjects(prods);
Produces the same result. It's only if I explicitly create new model instances that I get the get/set goodness:
var prods = [Vix.Prod.create({id:"yermom1", title:"yermom 1"}), {Vix.Prod.create(id:"yermom2", title:"yermom 2"})]
Is there a way to automatically type cast those vanilla objects to my Vix.Prod Ember Object? If not, am I the only one that really wants something like that? In Backbone one can set the model property on a collection. I suppose I can create a setter on my Controller to do something similar- just wondering if there is something built-in that I'm missing. Thanks!
No magic. I'd suggest do a loop wrapping the model.
var prods = [{id:"yermom1", title:"yermom 1"}, {id:"yermom2", title:"yermom 2"}];
for (var i = 0; i < prods.length; i++) {
prods[i] = Vix.Prod.create(prods[i]);
}
If I use ember as much as I hope to, I'm going to want a shortcut. So here's what I've done for now. I created a base Collection class that I use to create my Collections/Controllers:
Vix.Collection = Ember.ArrayController.extend({
model: null,
pushObject: function(obj) {
if (this.get('model') && obj.__proto__.constructor !== this.get('model')) {
obj = this.get('model').create(obj);
}
return this._super(obj);
},
pushObjects: function(objs) {
if (this.get('model')) {
objs = this._typecastArray(objs)
}
return this._super(objs);
},
set: function(prop, val) {
if (prop === 'content' && this.get('model')) {
val = this._typecastArray(val);
}
return this._super(prop, val);
},
_typecastArray: function(objs) {
var typecasted = [];
objs.forEach(function(obj){
if (obj.__proto__.constructor !== this.get('model')) {
obj = this.get('model').create(obj);
}
typecasted.push(obj);
}, this);
return typecasted;
}
})
Now when I call pushObject, pushObjects, or .set('collection', data), if the collection instance has a defined model property and the objects being added to the collection aren't already of that type, they'll be cast. Been working good so far, but I welcome any feedback.
You should have a look at ember-data: https://github.com/emberjs/data
It seems to fit your needs...
As of today, it's not yet production ready (as stated in the readme), but is quickly converging toward maturity, thanks to an active development.

Testing property set with a List in Rhino Mocks

I feel like I have lost my mind because I am sure I have done this before. Hopefully one of you can point me in the right direction.
Essentially I have an view that I want to test that the presenter is correctly setting the property with a list of objects. Example:
public ComplexDto{
public string name{get;set;}
public string description{get;set;}
}
public interface ITestView{
IList<ComplexDto> dto{get;set;}
}
Within the Presenter it sets a list like:
...
var dtos = new List<ComplexDto>();
dtos.add(new ComplexDto(){name="test name", description="this is some description"}
view.dto = dtos;
...
I need to test that that contents of the list of the dto work.
I have tried GetArgumentsForCallsMadeOn but I think this does not work with properties.
Thanks for any help!
EDIT
This should do it:
var view = MockRepository.GenerateMock<ITestView>();
var dtos = new List<ComplexDto>();
dtos.Add(new ComplexDto() {name = "test name", description = "this is some description"});
List<ComplexDto> passedIn;
view.Expect(v => v.dto).SetPropertyWithArgument(dtos).WhenCalled(mi => passedIn = (List<ComplexDto>) mi.Arguments[0]);
view.dto = dtos;
view.VerifyAllExpectations();