Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add load event #145

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});

});