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 ScarletsFrame #519

Merged
merged 6 commits into from
Feb 18, 2019
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
3 changes: 3 additions & 0 deletions frameworks/keyed/scarletsframe/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets" : [ "babel-preset-es2015"]
}
59 changes: 59 additions & 0 deletions frameworks/keyed/scarletsframe/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>ScarletsFrame-"keyed"</title>
<link href="/css/currentStyle.css" rel="stylesheet"/>
</head>
<body>
<div class="container" sf-controller="bench-mark">
<div class="jumbotron">
<div class="row">
<div class="col-md-6">
<h1>ScarletsFrame-"keyed"</h1>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='run' sf-click='b_run()'>Create 1,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='runlots' sf-click='b_runlots()'>Create 10,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='add' sf-click='b_add()'>Append 1,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='update' sf-click='b_update()'>Update every 10th row</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='clear' sf-click='b_clear()'>Clear</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='swaprows' sf-click='b_swaprows()'>Swap Rows</button>
</div>
</div>
</div>
</div>
</div>
<table class="table table-hover table-striped test-data">
<tbody id="tbody">
<tr sf-repeat-this="x in list" class="{{ x.status }}">
<td class="col-md-1">{{ x.id }}</td>
<td class="col-md-4">
<a class="lbl" sf-click="b_select(this)">{{ x.label }}</a>
</td>
<td class="col-md-1">
<a class="remove" sf-click="b_remove(this)">
<span class="remove glyphicon glyphicon-remove" aria-hidden="true"></span>
</a>
</td>
<td class="col-md-6"></td>
</tr>
</tbody>
</table>
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
</div>
<script src='dist/main.js'></script>
</body>
</html>
32 changes: 32 additions & 0 deletions frameworks/keyed/scarletsframe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "js-framework-benchmark-scarletsframe",
"version": "1.0.0",
"description": "ScarletsFrame demo",
"main": "index.js",
"js-framework-benchmark": {
"frameworkVersion": ""
},
"scripts": {
"build-dev": "webpack -w -d",
"build-prod": "webpack -p"
},
"keywords": [
"scarletsframe"
],
"author": "StefansArya",
"license": "Apache-2.0",
"homepage": "https://github.com/krausest/js-framework-benchmark",
"repository": {
"type": "git",
"url": "https://github.com/krausest/js-framework-benchmark.git"
},
"dependencies": {
"scarletsframe": "0.9.13"
},
"devDependencies": {
"babel-core": "6.24.1",
"babel-loader": "7.0.0",
"babel-preset-es2015": "6.24.1",
"webpack": "2.5.1"
}
}
143 changes: 143 additions & 0 deletions frameworks/keyed/scarletsframe/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
var sf = require('scarletsframe');
var $ = sf.dom;

// Declare variable for the model
sf.model.for('bench-mark', function(self){
self.list = [];
self.selected = -1;
});

// Declare functions that controlling the model
sf.controller.run('bench-mark', function(self, root){
var Measurer = root('measurer');

var adjectives = ["pretty", "large", "big", "small", "tall", "short", "long", "handsome", "plain", "quaint", "clean", "elegant", "easy", "angry", "crazy", "helpful", "mushy", "odd", "unsightly", "adorable", "important", "inexpensive", "cheap", "expensive", "fancy"];
var colours = ["red", "yellow", "blue", "green", "pink", "brown", "purple", "brown", "white", "black", "orange"];
var nouns = ["table", "chair", "house", "bbq", "desk", "car", "pony", "cookie", "sandwich", "burger", "pizza", "mouse", "keyboard"];

var nextId = 1;

function _random(max) {
return Math.round(Math.random()*1000)%max;
}

self.buildData = function(count = 1000){
var data = [];
for (var i = 0; i < count; i++)
data.push({
id: nextId++,
status:'',
label: adjectives[_random(adjectives.length)] + " " + colours[_random(colours.length)] + " " + nouns[_random(nouns.length)]
});

return data;
}

self.unselect = function(){
if(self.selected === -1) return;

if(self.list[self.selected] !== undefined){
self.list[self.selected].status = '';
self.list.softRefresh(self.selected);
}

self.selected = -1;
}

// Handle button
self.b_run = function(){
Measurer.start("run");
self.list = self.buildData();
self.selected = -1;
Measurer.stop();
}

self.b_runlots = function(){
Measurer.start("runLots");
self.list = self.buildData(10000);
self.selected = -1;
Measurer.stop();
}

self.b_add = function(){
Measurer.start("add");
self.list = self.list.concat(self.buildData(1000));
Measurer.stop();
}

self.b_update = function(){
Measurer.start("update");
for (var i = 0; i < self.list.length; i += 10) {
self.list[i].label += ' !!!';
self.list.softRefresh(i);
}
Measurer.stop();
}

self.b_clear = function(){
Measurer.start("clear");
self.list.splice(0);
self.selected = -1;
Measurer.stop();
}

self.b_swaprows = function(){
Measurer.start("swapRows");

if(self.list.length > 998)
self.list.swap(1, 998);

Measurer.stop();
}

self.b_select = function(el){
Measurer.start("select");
self.unselect();

var rowIndex = $.parent(el, '[sf-bind-list]');
self.selected = rowIndex = sf.model.index(rowIndex);

self.list[rowIndex].status = 'danger';
self.list.softRefresh(rowIndex);
Measurer.stop();
}

self.b_remove = function(el){
Measurer.start("delete");

var rowIndex = $.parent(el, '[sf-bind-list]');
rowIndex = sf.model.index(rowIndex);

self.list.splice(rowIndex, 1);

if(rowIndex === self.selected)
self.selected = -1;

Measurer.stop();
}
});

// Declare measure function in different scope
sf.controller.run('measurer', function(self){
var startTime;
var lastMeasure;

self.start = function(name) {
startTime = performance.now();
lastMeasure = name;
}
self.stop = function() {
var last = lastMeasure;
if (lastMeasure) {
window.setTimeout(function () {
lastMeasure = null;
var stop = performance.now();
var duration = 0;
console.log(last+" took "+(stop-startTime));
}, 0);
}
}
});

// We're not using dynamic resource loader
sf.loader.off();
40 changes: 40 additions & 0 deletions frameworks/keyed/scarletsframe/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';
var path = require('path')
var cache = {};
var loaders = [
{
test: /\.js$/,
loader: 'babel-loader'
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
}
];
var extensions = [
'.js', '.jsx', '.es6.js'
];

module.exports = [{
cache: cache,
module: {
loaders: loaders
},
entry: {
main: './src/main.js',
},
output: {
path: path.resolve(__dirname, "dist"),
filename: '[name].js'
},
resolve: {
extensions: extensions,
modules: [
__dirname,
path.resolve(__dirname, "src"),
"node_modules"
],
alias: {
}
}
}];
3 changes: 3 additions & 0 deletions frameworks/non-keyed/scarletsframe/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets" : [ "babel-preset-es2015"]
}
59 changes: 59 additions & 0 deletions frameworks/non-keyed/scarletsframe/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>ScarletsFrame-"keyed"</title>
<link href="/css/currentStyle.css" rel="stylesheet"/>
</head>
<body>
<div class="container" sf-controller="bench-mark">
<div class="jumbotron">
<div class="row">
<div class="col-md-6">
<h1>ScarletsFrame-"keyed"</h1>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='run' sf-click='b_run()'>Create 1,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='runlots' sf-click='b_runlots()'>Create 10,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='add' sf-click='b_add()'>Append 1,000 rows</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='update' sf-click='b_update()'>Update every 10th row</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='clear' sf-click='b_clear()'>Clear</button>
</div>
<div class="col-sm-6 smallpad">
<button type='button' class='btn btn-primary btn-block' id='swaprows' sf-click='b_swaprows()'>Swap Rows</button>
</div>
</div>
</div>
</div>
</div>
<table class="table table-hover table-striped test-data">
<tbody id="tbody">
<tr sf-repeat-this="x in list" class="{{ x.isSelected ? 'danger' : '' }}">
<td class="col-md-1">{{ x.id }}</td>
<td class="col-md-4">
<a class="lbl" sf-click="b_select(this)">{{ x.label }}</a>
</td>
<td class="col-md-1">
<a class="remove" sf-click="b_remove(this)">
<span class="remove glyphicon glyphicon-remove" aria-hidden="true"></span>
</a>
</td>
<td class="col-md-6"></td>
</tr>
</tbody>
</table>
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
</div>
<script src='dist/main.js'></script>
</body>
</html>
32 changes: 32 additions & 0 deletions frameworks/non-keyed/scarletsframe/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "js-framework-benchmark-scarletsframe",
"version": "1.0.0",
"description": "ScarletsFrame demo",
"main": "index.js",
"js-framework-benchmark": {
"frameworkVersion": ""
},
"scripts": {
"build-dev": "webpack -w -d",
"build-prod": "webpack -p"
},
"keywords": [
"scarletsframe"
],
"author": "StefansArya",
"license": "Apache-2.0",
"homepage": "https://github.com/krausest/js-framework-benchmark",
"repository": {
"type": "git",
"url": "https://github.com/krausest/js-framework-benchmark.git"
},
"dependencies": {
"scarletsframe": "0.10.4"
},
"devDependencies": {
"babel-core": "6.24.1",
"babel-loader": "7.0.0",
"babel-preset-es2015": "6.24.1",
"webpack": "2.5.1"
}
}
Loading