是否可以使用TypeScript类创建js-data资源定义?
我一般想要的是对计算属性和实例方法定义进行完全打字支持.
什么是令人敬畏的是这样的:
class SomeModel
{
public someBusinessModelValue = 'foo';
public someMoreValues = 'bar';
public get someComputedProperty()
{
return this.someBusinessModelValue + someMoreValues;
}
public instanceMethod(param: string)
{
return this.someMoveValues.search(param);
}
}
Run Code Online (Sandbox Code Playgroud)
然后
DS.defineResource(fromClass('name', '/endpoint', 'idAttr', SomeModel));
Run Code Online (Sandbox Code Playgroud)
或者更进一步,并将其定义为
class SomeModelStore extends SomeModel
{
name = 'name';
endpoint = 'endpoint';
idAttribute = 'idAttr';
relations =
{
//[...]
}
}
Run Code Online (Sandbox Code Playgroud)
并使用它
DS.defineResource(SomeModelStore);
Run Code Online (Sandbox Code Playgroud)
请注意,这些只是对我希望它看起来像什么的一些想法,我知道它可能不会完全像那样.
我通过sails.js将js-data(和js-data-angular)与套接字结合使用.当通过套接字创建/更新新项目时,我想在我的ui中引起注意.
我想向对象添加"更新"属性,但不希望无意中将其持久保存到数据库中.
有没有办法在js-data对象上挂起非持久性属性?