Skip to content

Commit

Permalink
refactor: workaround tree shakable expression in ngrid/state
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomiassaf committed Jun 13, 2019
1 parent b195880 commit abae5a5
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 273 deletions.
4 changes: 2 additions & 2 deletions libs/ngrid-material/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@pebula/ngrid-material",
"version": "1.0.0-alpha.21",
"version": "1.0.0-alpha.22",
"peerDependencies": {
"@angular/material": "^7.3.1",
"@pebula/ngrid": "1.0.0-alpha.21"
"@pebula/ngrid": "1.0.0-alpha.22"
}
}
2 changes: 1 addition & 1 deletion libs/ngrid/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pebula/ngrid",
"version": "1.0.0-alpha.21",
"version": "1.0.0-alpha.22",
"peerDependencies": {
"@angular/common": "^7.2.3",
"@angular/core": "^7.2.3",
Expand Down
4 changes: 4 additions & 0 deletions libs/ngrid/src/lib/ext/table-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ export interface TablePluginMetadata<P extends keyof PblNgridPluginExtension = k
? PblNgridPluginExtensionFactories[P]
: never
;
runOnce?: () => void;
}

export function TablePlugin(metadata: TablePluginMetadata) {
if (metadata.runOnce) {
metadata.runOnce();
}
return target => {
PLUGIN_STORE.set(metadata.id, { ...metadata, target });
}
Expand Down
9 changes: 9 additions & 0 deletions libs/ngrid/state/src/lib/core/built-in-handlers/_register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { registerGridHandlers } from './grid-primitives/index';
import { registerColumnOrderHandlers } from './column-order/index';
import { registerColumnDefHandlers } from './column-def/index';

export function registerBuiltInHandlers() {
registerGridHandlers();
registerColumnOrderHandlers();
registerColumnDefHandlers();
}
256 changes: 129 additions & 127 deletions libs/ngrid/state/src/lib/core/built-in-handlers/column-def/children.ts
Original file line number Diff line number Diff line change
@@ -1,144 +1,146 @@
import { PblColumnTypeDefinition } from '@pebula/ngrid';
import { createStateChunkHandler } from '../../handling';

/* ====================================================================================================================================================== */

createStateChunkHandler('dataColumn')
.requiredKeys('id', 'prop')
.handleKeys(
'label', 'css', 'type', 'width', 'minWidth', 'maxWidth', // PblNgridBaseColumnState (all optional)
'headerType', 'footerType', 'sort', 'sortAlias', 'editable', 'pin' // All Optional
)
.serialize( (key, ctx) => {
const c = ctx.data.activeColumn || ctx.data.pblColumn;
if (c) {
export function registerColumnDefChildHandlers() {
/* ====================================================================================================================================================== */

createStateChunkHandler('dataColumn')
.requiredKeys('id', 'prop')
.handleKeys(
'label', 'css', 'type', 'width', 'minWidth', 'maxWidth', // PblNgridBaseColumnState (all optional)
'headerType', 'footerType', 'sort', 'sortAlias', 'editable', 'pin' // All Optional
)
.serialize( (key, ctx) => {
const c = ctx.data.activeColumn || ctx.data.pblColumn;
if (c) {
switch (key) {
case 'prop':
return c.orgProp;
default:
break;
}
}

const value = c ? c[key] : ctx.source[key];

switch (key) {
case 'prop':
return c.orgProp;
case 'sort':
if (typeof value === 'boolean') {
return value;
} else {
return;
}
default:
break;
}
}

const value = c ? c[key] : ctx.source[key];

switch (key) {
case 'sort':
if (typeof value === 'boolean') {
return value;
} else {
return;
return value;
})
.deserialize( (key, stateValue, ctx) => {
const { activeColumn } = ctx.data;
if (activeColumn) {
switch (key) {
case 'width':
activeColumn.updateWidth(true, stateValue as any);
break;
}
default:
break;
}

return value;
})
.deserialize( (key, stateValue, ctx) => {
const { activeColumn } = ctx.data;
if (activeColumn) {
switch (key) {
case 'width':
activeColumn.updateWidth(true, stateValue as any);
break;
}
}
if (ctx.source) {
switch (key) {
case 'prop':
return;
case 'type':
case 'headerType':
case 'footerType':
const typeValue = ctx.source[key];
const stateTypeDef: PblColumnTypeDefinition = stateValue as any;
if (stateTypeDef && typeof stateTypeDef !== 'string' && typeValue && typeof typeValue !== 'string') {
typeValue.name = stateTypeDef.name;
if (stateTypeDef.data) {
typeValue.data = Object.assign(typeValue.data || {}, stateTypeDef.data);
}
if (ctx.source) {
switch (key) {
case 'prop':
return;
}
break;
case 'type':
case 'headerType':
case 'footerType':
const typeValue = ctx.source[key];
const stateTypeDef: PblColumnTypeDefinition = stateValue as any;
if (stateTypeDef && typeof stateTypeDef !== 'string' && typeValue && typeof typeValue !== 'string') {
typeValue.name = stateTypeDef.name;
if (stateTypeDef.data) {
typeValue.data = Object.assign(typeValue.data || {}, stateTypeDef.data);
}
return;
}
break;
}
ctx.source[key] = stateValue;
}

})
.register();

/* ====================================================================================================================================================== */

createStateChunkHandler('dataMetaRow')
.handleKeys('rowClassName', 'type') // All Optional
.serialize( (key, ctx) => {
const active = ctx.data.active || ctx.source;
if (active) {
return active[key];
}
ctx.source[key] = stateValue;
}

})
.register();

/* ====================================================================================================================================================== */

createStateChunkHandler('dataMetaRow')
.handleKeys('rowClassName', 'type') // All Optional
.serialize( (key, ctx) => {
const active = ctx.data.active || ctx.source;
if (active) {
return active[key];
}
})
.deserialize( (key, stateValue, ctx) => ctx.source[key] = stateValue )
.register();

/* ====================================================================================================================================================== */

createStateChunkHandler('metaRow')
// Note that we are not handling `cols`, this should be called from the parent, as a different child chunk handling process for each column
.handleKeys(
'rowClassName', 'type', // All Optional like dataMetaRow
'rowIndex', // Required
})
.deserialize( (key, stateValue, ctx) => ctx.source[key] = stateValue )
.register();

/* ====================================================================================================================================================== */

createStateChunkHandler('metaRow')
// Note that we are not handling `cols`, this should be called from the parent, as a different child chunk handling process for each column
.handleKeys(
'rowClassName', 'type', // All Optional like dataMetaRow
'rowIndex', // Required
)
.serialize( (key, ctx) => {
return ctx.source[key];
})
.deserialize( (key, stateValue, ctx) => {

})
.register();

/* ====================================================================================================================================================== */

createStateChunkHandler('metaGroupRow')
// Note that we are not handling `cols`, this should be called from the parent, as a different child chunk handling process for each column
.handleKeys(
'rowClassName', 'type', // All Optional like dataMetaRow
'rowIndex', // Required
)
.serialize( (key, ctx) => {
return ctx.source[key];
})
.deserialize( (key, stateValue, ctx) => {

})
.register();

/* ====================================================================================================================================================== */

createStateChunkHandler('metaColumn')
.requiredKeys('kind', 'rowIndex')
.handleKeys(
'id', 'label', 'css', 'type', 'width', 'minWidth', 'maxWidth', // PblNgridBaseColumnState (all optional)
)
.serialize( (key, ctx) => {
return ctx.source[key];
})
.deserialize( (key, stateValue, ctx) => {
.serialize( (key, ctx) => {
return ctx.source[key];
})
.deserialize( (key, stateValue, ctx) => {

})
.register();
})
.register();

/* ====================================================================================================================================================== */
/* ====================================================================================================================================================== */

createStateChunkHandler('metaGroupRow')
// Note that we are not handling `cols`, this should be called from the parent, as a different child chunk handling process for each column
.handleKeys(
'rowClassName', 'type', // All Optional like dataMetaRow
'rowIndex', // Required
createStateChunkHandler('metaGroupColumn')
.requiredKeys('prop', 'rowIndex', 'span')
.handleKeys(
'id', 'label', 'css', 'type', 'width', 'minWidth', 'maxWidth', // PblNgridBaseColumnState (all optional)
)
.serialize( (key, ctx) => {
return ctx.source[key];
})
.deserialize( (key, stateValue, ctx) => {

})
.register();

/* ====================================================================================================================================================== */

createStateChunkHandler('metaColumn')
.requiredKeys('kind', 'rowIndex')
.handleKeys(
'id', 'label', 'css', 'type', 'width', 'minWidth', 'maxWidth', // PblNgridBaseColumnState (all optional)
)
.serialize( (key, ctx) => {
return ctx.source[key];
})
.deserialize( (key, stateValue, ctx) => {

})
.register();

/* ====================================================================================================================================================== */

createStateChunkHandler('metaGroupColumn')
.requiredKeys('prop', 'rowIndex', 'span')
.handleKeys(
'id', 'label', 'css', 'type', 'width', 'minWidth', 'maxWidth', // PblNgridBaseColumnState (all optional)
)
.serialize( (key, ctx) => {
return ctx.source[key];
})
.deserialize( (key, stateValue, ctx) => {

})
.register();
.serialize( (key, ctx) => {
return ctx.source[key];
})
.deserialize( (key, stateValue, ctx) => {

})
.register();
}
Loading

0 comments on commit abae5a5

Please sign in to comment.