Skip to content

Commit

Permalink
add load event (#145)
Browse files Browse the repository at this point in the history
* add load event

* 2.11.6
  • Loading branch information
kbarbounakis committed May 12, 2024
1 parent 9f3bad0 commit f036189
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions data-model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import {DataAssociationMapping, DataContext, DataField} from "./types";
import {DataModelBase, SequentialEventEmitter} from "@themost/common";
import {DataQueryable} from "./data-queryable";
import {SyncSeriesEventEmitter} from '@themost/events';

export declare class DataModel extends SequentialEventEmitter implements DataModelBase {

static load: SyncSeriesEventEmitter<{ target: DataModel }>;

constructor(obj:any);

name: string;
Expand Down
7 changes: 6 additions & 1 deletion data-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var {ZeroOrOneMultiplicityListener} = require('./zero-or-one-multiplicity');
var {OnNestedQueryListener} = require('./OnNestedQueryListener');
var {OnExecuteNestedQueryable} = require('./OnExecuteNestedQueryable');
var {hasOwnProperty} = require('./has-own-property');
var { SyncSeriesEventEmitter } = require('@themost/events');
require('@themost/promise-sequence');
var DataObjectState = types.DataObjectState;
/**
Expand Down Expand Up @@ -564,7 +565,9 @@ DataModel.prototype.getDataObjectType = function() {
* Initializes the current data model. This method is used for extending the behaviour of an install of DataModel class.
*/
DataModel.prototype.initialize = function() {
//
DataModel.load.emit({
target: this
});
};

/**
Expand Down Expand Up @@ -3315,6 +3318,8 @@ DataModel.prototype.upsertAsync = function(obj) {
});
}

DataModel.load = new SyncSeriesEventEmitter();

module.exports = {
DataModel
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@themost/data",
"version": "2.11.5",
"version": "2.11.6",
"description": "MOST Web Framework Codename Blueshift - Data module",
"main": "index.js",
"scripts": {
Expand Down
13 changes: 12 additions & 1 deletion spec/DataModel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {DataModel, EdmMapping, DataContext} from '../index';
import { TestApplication } from './TestApplication';
import { resolve } from 'path';
import {SqliteAdapter} from '@themost/sqlite';

class Employee {
public EmployeeID?: number;
Expand Down Expand Up @@ -69,7 +70,7 @@ describe('DataModel', () => {
});

it('should use migrateAsync', async () => {
const db: TestAdapter = context.db as TestAdapter;
const db = context.db as SqliteAdapter;
let exists = await db.table('OtherProducts').existsAsync();
expect(exists).toBeFalsy();
const upgraded = await context.model('OtherProduct').migrateAsync();
Expand All @@ -83,4 +84,14 @@ describe('DataModel', () => {
});
});

it('should use load event', async () => {
DataModel.load.subscribeOnce((event) => {
event.target.caching = 'always';
});
let model = context.model('Employee');
expect(model.caching).toBe('always');
model = context.model('Employee');
expect(model.caching).toBe('none');
});

});

0 comments on commit f036189

Please sign in to comment.