Skip to content

Commit 861159a

Browse files
committed
Merge branch 'snowbldr-fntags_0.3.1'
2 parents 0c2db0f + a2556e5 commit 861159a

File tree

6 files changed

+124
-102
lines changed

6 files changed

+124
-102
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ As you can see the mean duration for create 1000 rows was 144 msecs.
158158
You can also check whether the implementation appears to be compliant to the rules:
159159

160160
```
161-
npm run check keyed/vanillajs
161+
npm run isKeyed keyed/vanillajs
162162
```
163163

164164
If it finds anything it'll report an ERROR.
@@ -298,7 +298,7 @@ Contributions are very welcome. Please use the following rules:
298298
- Webdriver-ts must be able to run the perf tests for the contribution. This means that all buttons (like "Create 1,000 rows") must have the correct id e.g. like in vanillajs. Using shadow DOM is a real pain for webdriver. The closer you can get to polymer the higher the chances I can make that contribution work.
299299
- Don't change the ids in the index.html, since the automated benchmarking relies on those ids.
300300
- Please push only files in your framework folder (not index.html or results.json)
301-
- **Please make sure your implementation is validated by the test tool.** cd to webdriver-ts and invoke it with `npm run check [keyed|non-keyed]/[FrameworkName]`. It'll print an error if your framework behaves other as specified. It'll print a big ERROR explaining if it isn't happy with the implementation. Some common errors include:
301+
- **Please make sure your implementation is validated by the test tool.** cd to webdriver-ts and invoke it with `npm run isKeyed [keyed|non-keyed]/[FrameworkName]`. It'll print an error if your framework behaves other as specified. It'll print a big ERROR explaining if it isn't happy with the implementation. Some common errors include:
302302
- Your package.json is missing some required fields
303303
- Incorrect classification (Keyed/NonKeyed)
304304
- You have gzipped files in /dist (unfortunately the web server prefers these when they exist)

frameworks/keyed/fntags/build.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
const fs = require( 'fs-extra' )
22
const terser = require( 'terser' )
33

4-
if( fs.existsSync( 'dist' ) ) fs.removeSync( 'dist' )
5-
fs.mkdirSync( 'dist' )
4+
async function build() {
65

7-
const minify = ( file ) => {
8-
let content = fs.readFileSync( file, 'utf8' )
9-
if( process.argv[ 2 ] === 'dev' ) {
10-
return content
11-
} else {
12-
const code = terser.minify( content ).code
13-
if( !code ) throw new Error( `failed to minify ${file}` ).stack
14-
return code
6+
if( await fs.exists( 'dist' ) ) await fs.remove( 'dist' )
7+
await fs.mkdir( 'dist' )
8+
9+
const minify = async ( file ) => {
10+
let content = await fs.readFile( file, 'utf8' )
11+
if( process.argv[2] === 'dev' ) {
12+
return content
13+
} else {
14+
let minifyOutput = await terser.minify( content, {module: true, ecma: 2015} );
15+
if( minifyOutput.error ) {
16+
const err = new Error( `failed to minify ${file}` )
17+
err.stack += `\nCaused By: ${minifyOutput.error.stack}`
18+
throw err
19+
}
20+
return minifyOutput.code
21+
}
1522
}
23+
await fs.writeFile( 'dist/fntags.min.js', await minify( 'node_modules/@srfnstack/fntags/src/fntags.mjs' ) )
24+
await fs.writeFile( 'dist/Main.js', await minify( 'src/Main.js' ) )
1625
}
17-
fs.writeFileSync('dist/fntags.min.js', minify('node_modules/@srfnstack/fntags/src/fntags.mjs'))
18-
fs.writeFileSync( 'dist/Main.js', minify( 'src/Main.js' ) )
26+
27+
build().catch(e => {throw e})

frameworks/keyed/fntags/package-lock.json

Lines changed: 25 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frameworks/keyed/fntags/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
},
1313
"author": "Robert Kempton",
1414
"dependencies": {
15-
"@srfnstack/fntags": "0.1.7"
15+
"@srfnstack/fntags": "0.3.3"
1616
},
1717
"devDependencies": {
1818
"fs-extra": "8.1.0",
19-
"terser": "4.3.8"
19+
"terser": "5.10.0"
2020
}
2121
}

frameworks/keyed/fntags/src/Main.js

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { fnstate, h } from './fntags.min.js'
1+
import { fnstate, fntemplate, h } from './fntags.min.js'
22

33
let data = fnstate( [], d => d.id )
44

5-
function random( max ) { return Math.round( Math.random() * 1000 ) % max }
5+
function random( max ) {
6+
return Math.round( Math.random() * 1000 ) % max
7+
}
68

79
const A = ['pretty', 'large', 'big', 'small', 'tall', 'short', 'long', 'handsome', 'plain', 'quaint', 'clean',
810
'elegant', 'easy', 'angry', 'crazy', 'helpful', 'mushy', 'odd', 'unsightly', 'adorable', 'important', 'inexpensive',
@@ -16,82 +18,85 @@ let nextId = 1
1618
function buildData( count ) {
1719
const newData = new Array( count )
1820
for( let i = 0; i < count; i++ ) {
19-
newData[ i ] = {
21+
newData[i] = {
2022
id: nextId++,
21-
label: `${A[ random( A.length ) ]} ${C[ random( C.length ) ]} ${N[ random( N.length ) ]}`
23+
label: `${A[random( A.length )]} ${C[random( C.length )]} ${N[random( N.length )]}`
2224
}
2325
}
2426
return newData
2527
}
2628

2729
const Button = ( id, title, onclick ) =>
2830
h( 'div', { class: 'col-sm-6 smallpad' },
29-
h( 'button', { id, type: 'button', class: 'btn btn-primary btn-block', onclick: onclick }, title )
31+
h( 'button', { id, type: 'button', class: 'btn btn-primary btn-block', onclick: onclick }, title )
32+
)
33+
34+
const row = fntemplate( ctx =>
35+
h( 'tr', { id: ctx( 'id' ), class: ctx( 'rowClass' ), onclick: ctx( 'rowClick' ) },
36+
h( 'td', { class: 'col-md-1' }, ctx( 'id' ) ),
37+
h( 'td', { class: 'col-md-4' }, h( 'a', { class: 'lbl' }, ctx( 'label' ) ) ),
38+
h( 'td', { class: 'col-md-1' },
39+
h( 'a', h( 'span', {
40+
onclick: ctx( 'removeRow' ),
41+
class: 'glyphicon glyphicon-remove',
42+
'aria-hidden': 'true'
43+
} )
44+
)
45+
),
46+
h( 'td', { class: 'col-md-6' } )
3047
)
48+
)
3149

3250
document.body.append(
3351
h( 'div', { class: 'container' },
34-
h( 'div', { class: 'jumbotron' },
35-
h( 'div', { class: 'row' },
36-
h( 'div', { class: 'col-md-6' },
37-
h( 'h1', 'fntags keyed' )
38-
),
39-
h( 'div', { class: 'col-md-6' },
40-
h( 'div', { class: 'row' },
41-
Button( 'run', 'Create 1,000 rows', () => data( buildData( 1000 ) ) ),
42-
Button( 'runlots', 'Create 10,000 rows', () => data( buildData( 10000 ) ) ),
43-
Button( 'add', 'Append 1,000 rows', () => data( data().concat( buildData( 1000 ) ) ) ),
44-
Button( 'update', 'Update every 10th row', () => {
45-
let items = data()
46-
for( let i = 0; i < items.length; i += 10 ) {
47-
let d = items[ i ]
48-
let it = d()
49-
it.label += ' !!!'
50-
d( it )
51-
}
52-
} ),
53-
Button( 'clear', 'Clear', () => data( [] ) ),
54-
Button( 'swaprows', 'Swap Rows', () => {
55-
const d = data()
56-
if( d.length > 998 ) {
57-
const a = d[ 1 ]
58-
d[ 1 ] = d[ 998 ]
59-
d[ 998 ] = a
60-
}
61-
data( d )
62-
} )
63-
)
64-
)
65-
)
66-
),
67-
h( 'table', { class: 'table table-hover table-striped test-data' },
68-
data.bindValues( h( 'tbody' ), ( item ) =>
69-
h( 'tr', {
70-
id: item().id,
71-
class: item.bindSelectAttr( () => data.selected() === item().id ? 'danger' : '' ),
72-
onclick: () => data.select( item().id )
73-
},
74-
h( 'td', {
75-
class: 'col-md-1'
76-
},
77-
item().id
78-
),
79-
h( 'td', { class: 'col-md-4' },
80-
h( 'a', { class: 'lbl' }, item.bindAs( () => item().label ) ) ),
81-
h( 'td', { class: 'col-md-1' },
82-
h( 'a',
83-
h( 'span', {
84-
onclick: ( e ) => {
85-
e.stopPropagation()
86-
data( data().filter( d => d().id !== item().id ) )
87-
},
88-
class: 'glyphicon glyphicon-remove', 'aria-hidden': 'true'
89-
} )
52+
h( 'div', { class: 'jumbotron' },
53+
h( 'div', { class: 'row' },
54+
h( 'div', { class: 'col-md-6' },
55+
h( 'h1', 'fntags keyed' )
56+
),
57+
h( 'div', { class: 'col-md-6' },
58+
h( 'div', { class: 'row' },
59+
Button( 'run', 'Create 1,000 rows', () => data( buildData( 1000 ) ) ),
60+
Button( 'runlots', 'Create 10,000 rows', () => data( buildData( 10000 ) ) ),
61+
Button( 'add', 'Append 1,000 rows', () => data( data().concat( buildData( 1000 ) ) ) ),
62+
Button( 'update', 'Update every 10th row', () => {
63+
let items = data()
64+
for( let i = 0; i < items.length; i += 10 ) {
65+
let d = items[i]
66+
let it = d()
67+
it.label += ' !!!'
68+
d( it )
69+
}
70+
} ),
71+
Button( 'clear', 'Clear', () => data( [] ) ),
72+
Button( 'swaprows', 'Swap Rows', () => {
73+
const d = data()
74+
if( d.length > 998 ) {
75+
const a = d[1]
76+
d[1] = d[998]
77+
d[998] = a
78+
}
79+
data( d )
80+
} )
9081
)
91-
),
92-
h( 'td', { class: 'col-md-6' } )
93-
) )
94-
)
95-
),
96-
h( 'span', { class: 'preloadicon glyphicon glyphicon-remove', 'aria-hidden': 'true' } )
97-
)
82+
)
83+
)
84+
),
85+
h( 'table', { class: 'table table-hover table-striped test-data' },
86+
data.bindChildren( h( 'tbody' ), item =>
87+
row( {
88+
id: item().id,
89+
label: item.bindAs( () => item().label ),
90+
rowClass: item.bindSelectAttr( () => data.selected() === item().id ? 'danger' : '' ),
91+
rowClick: () => data.select( item().id ),
92+
removeRow: ( e ) => {
93+
e.stopPropagation()
94+
data( data().filter( d => d().id !== item().id ) )
95+
}
96+
} )
97+
)
98+
),
99+
h( 'span', { class: 'preloadicon glyphicon glyphicon-remove', 'aria-hidden': 'true' } )
100+
)
101+
)
102+

index.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)