
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@cherry-tomato/core
Advanced tools
[](https://www.npmjs.org/package/@cherry-tomato/core)
cherry-tomato 基于面向对象的设计理念,主要专注于在前端领域里,抽象数据模型和业务逻辑。让逻辑和视图解耦,提高项目代码的可复用性。
cherry-tomato 基于 typescript 开发,是纯粹的 js 代码。
npm install --save @cherry-tomato/core
Model类Collection类,是多个Model的集合(类似数组)Model 事件基于此Model的装饰器基础模型类。最基础也是重要的,一般需要配合 attribute 装饰器使用
import {
Model,
attribute
} from '@cherry-tomato/core';
class CustomModel extends Model {
@attribute()
accessor text = 'a'; // 设置默认值为a
}
const custom = new CustomModel();
custom.text === 'a';
[attributes] 初始化属性const custom = new CustomModel({ text: 'b' });
custom.text === 'b';
get(key) 获取属性,设置过的属性可以被通过attribute装饰过的属性直接获取set(key, value) 设置属性reset(value) 重设所有属性remove(key) 删除对应属性使用例子如下
custom.set('text', 'c');
custom.text === 'c';
custom.get('text') === 'c';
class fields的方式设置默认值model设置了2个生命周期,同时会抛出同名的Event
set, 但还没有执行set 操作时,此时 this.get(attributeName) === prevAttributes.get(attributeName)set, set执行成功, 此时 this.get(attributeName) === nextAttributes.get(attributeName)继承自Model, 扩充对数组类型的支持。会更具static Model的静态属性自动转换children对对应的对象实例
import {
Collection
} from '@cherry-tomato/core';
class CustomCollection extends Collection<CustomModel> {
static Model = CustomModel;
// hook: before update children (includes remove, add)
collectionWillUpdateChildren () {}
// hook: after update children (includes remove, add)
collectionDidUpdateChildren () {}
}
const customCollection = new CustomCollection();
customCollection.resetChildren(
[
{
text: 'a'
},
{
text: 'b'
}
]
);
customCollection.children[0] instanceof CustomModel;
customCollection.children[0].text === 'a';
customCollection.children[1].text === 'b';
[initialAttributes] 同Model的initialAttributesModel - 用于自动生成子元素的构造函数Model 所有函数Array的各种方法 已支持forEach, map, reduce, reduceRight, slice, filter, find, findIndex, some, every, includes, indexOf
customCollection.forEach((custom) => {
console.log(custom.text)
})
// 'a'
// 'b'
特别注意:filter、slice、concat 返回的是一个collection实力addChild - 添加一个子元素到最后,并添加监听,会自动使用设置的 Static Model 去创建
removeChild - 移除一个子元素,并取消监听,会自动使用设置的 Static Model 去创建
resetChildren - 重设所有子元素,并添加监听,会自动使用设置的 Static Model 去创建
merge 效果同 concat,同时会修改自身Model的所有hooksmodelDidUpdate, collectionDidUpdateChildren, collectionDidUpdateChildren事件后触发参考Model就可以了
高级用法,关联不同的实例
import {
Model,
connect,
attribute
} from '@cherry-tomato/core';
class ModelA extends Model {
@attribute()
accessor text = 'a';
}
class ModelB extends Model {
@connect()
a = new ModelA();
}
const b = new ModelB({
a: {
text: 'aa'
}
});
b.a instanceof ModelA;
b.a.text === 'aa';
待补充
FAQs
[](https://www.npmjs.org/package/@cherry-tomato/core)
The npm package @cherry-tomato/core receives a total of 5 weekly downloads. As such, @cherry-tomato/core popularity was classified as not popular.
We found that @cherry-tomato/core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.