├── .gitignore ├── LICENSE ├── README ├── bower.json ├── fx-listener-test.html ├── fx-listener.html ├── fx-observer-test.html ├── fx-observer.html ├── fx-route.html ├── fx-shared-instance-test.html ├── fx-shared-instance.html ├── fx-task-queue.html ├── fx-view-aware.html ├── fx-view.html ├── fx-worker.html ├── karma.conf.js ├── mocha.conf.js ├── notes.txt.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | bower_components -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 The Chromium Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | A framework for rapidly building polymer apps. 2 | 3 | Depends on sugar.js -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fx-framework", 3 | "version": "0.0.0", 4 | "authors": [ 5 | "Elliott Sprehn " 6 | ], 7 | "description": "A framework for rapidly building polymer apps.", 8 | "license": "https://chromium.googlesource.com/chromium/src.git/+/master/LICENSE", 9 | "private": true, 10 | "dependencies": { 11 | "polymer": "Polymer/polymer", 12 | "sugar": "andrewplummer/sugar#~1.4.1" 13 | }, 14 | "ignore": [ 15 | "**/.*", 16 | "node_modules", 17 | "bower_components", 18 | "test", 19 | "tests" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /fx-listener-test.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 104 | -------------------------------------------------------------------------------- /fx-listener.html: -------------------------------------------------------------------------------- 1 | 23 | 24 | 25 | 26 | 131 | -------------------------------------------------------------------------------- /fx-observer-test.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 116 | -------------------------------------------------------------------------------- /fx-observer.html: -------------------------------------------------------------------------------- 1 | 6 | 22 | 23 | 24 | 25 | 95 | 96 | -------------------------------------------------------------------------------- /fx-route.html: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /fx-shared-instance-test.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 158 | -------------------------------------------------------------------------------- /fx-shared-instance.html: -------------------------------------------------------------------------------- 1 | 29 | 30 | 31 | 32 | 103 | 104 | -------------------------------------------------------------------------------- /fx-task-queue.html: -------------------------------------------------------------------------------- 1 | 21 | 22 | 23 | 24 | 158 | 159 | -------------------------------------------------------------------------------- /fx-view-aware.html: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /fx-view.html: -------------------------------------------------------------------------------- 1 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /fx-worker.html: -------------------------------------------------------------------------------- 1 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | module.exports = function(config) { 2 | config.set({ 3 | // Up a level since we expect to be embedded inside bower_components/ in 4 | // parallel to polymer itself. 5 | basePath: "../", 6 | frameworks: ["mocha"], 7 | files: [ 8 | // Test runner deps. 9 | "fx-framework/node_modules/chai/chai.js", 10 | "fx-framework/mocha.conf.js", 11 | 12 | // Framework core deps. 13 | "platform/platform.js", 14 | "sugar/release/sugar.min.js", 15 | 16 | // The actual tests. 17 | "fx-framework/*-test.html", 18 | 19 | // We need to be able to serve these files, but don't want to have them 20 | // loaded automatically. 21 | {pattern: "fx-framework/*.html", included: false}, 22 | {pattern: "platform/*", included: false}, 23 | {pattern: "polymer/*", included: false}, 24 | ], 25 | reporters: ["progress"], 26 | port: 9876, 27 | colors: true, 28 | logLevel: config.LOG_INFO, 29 | autoWatch: true, 30 | browsers: ["ChromeCanary"], 31 | singleRun: false, 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /mocha.conf.js: -------------------------------------------------------------------------------- 1 | mocha.setup({ 2 | ui: 'bdd', 3 | ignoreLeaks: true 4 | }); 5 | 6 | var assert = chai.assert; 7 | -------------------------------------------------------------------------------- /notes.txt.js: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Sends and observes notifications by broadcasting notify events. 4 | 5 | Usage: 6 | 7 | 8 | 9 | FxObserver.notify("example", relatedData); 10 | 11 | FxObserver.notifyAsync("example", relatedData).then(function() { 12 | // ... 13 | }); 14 | */ 15 | @Element("fx-observer") 16 | @Event("notify") 17 | class FxObserver extends HTMLElement { 18 | string for; 19 | 20 | void notify(optional Object data); 21 | Promise notifyAsync(optional Object data); 22 | 23 | static void notify(string type, optional Object data); 24 | static Promise notifyAsync(string type, option Object data); 25 | } 26 | 27 | /* 28 | Implements the monostate pattern. Allows notifying all instances of a 29 | given instanceType (tagName by default) of some event. 30 | 31 | Note that the default of tagName is not friendly to subclassing so you 32 | should specify an explicit instanceType if you expect your component to 33 | be subclassed. 34 | 35 | Usage: 36 | 37 | 38 | 41 | 53 | 54 | */ 55 | @Element("fx-shared-instance") 56 | class FxSharedInstance extends HTMLElement { 57 | string instanceType; 58 | 59 | void notifyInstances(string method, optional Object data); 60 | Promise notifyInstancesAsync(string method, optional Object data); 61 | 62 | Array getInstances(); 63 | 64 | static getInstances(string instanceType); 65 | static void notify(string instanceType, string method, optional Object data); 66 | static Promise notifyAsync(string instanceType, string method, optional Object data); 67 | } 68 | 69 | /* 70 | Listens for external elements and notifies locally. Target can be any window 71 | accessible property path, for example "document" or "screen.orientation". By 72 | default if no path is specified events are listened for on the window 73 | itself. 74 | 75 | The presence of an attribute that starts with "on-" will trigger a listener 76 | on the target for the event name following the dash. This works implicitly 77 | in polymer's declarative event handlers. If you're not using polymer, or are 78 | creating an element programatically you can add an attribute 79 | "on-{eventname}" to the element with no value. 80 | 81 | Usage: 82 | 83 | 84 | */ 85 | @Element("fx-listener") 86 | class FxListener extends FxSharedInstance { 87 | string target; 88 | } 89 | 90 | /* 91 | Declares a route in a fx-view map. When the route path is matched the 92 | specified element will be created. 93 | 94 | Usage: 95 | 96 | 97 | */ 98 | @Element("fx-route") 99 | class FxRoute extends HTMLElement { 100 | string path; 101 | string element; 102 | Element createView(Object params); 103 | boolean matchPath(string path); 104 | } 105 | 106 | /* 107 | Declares the view map for an application. There should only be one per 108 | application. Components that want same domain links to instead route to 109 | views should embed a component. 110 | 111 | Events: 112 | "viewchange": Before the view is changed. 113 | 114 | Usage: 115 | 116 | 117 | 118 | 119 | */ 120 | @Element("fx-view") 121 | class FxView extends HTMLElement { 122 | Element activeView; 123 | Promise createView(); 124 | void loadRoute(string path); 125 | } 126 | 127 | /* 128 | Put this component inside other components that contain elements 129 | (inside the same ShadowRoot) where clicks on those links should instead 130 | navigate to views instead of reloading the page. 131 | */ 132 | @Element("fx-view-aware") 133 | class FxViewAware extends HTMLElement { } 134 | 135 | /* 136 | Schedules work to execute, will run the passed function, and replace it 137 | with the newly returned function, repeatedly until the work runs out or 138 | the workLimit is reached in ms. If the limit is reached and there are still 139 | functions to run then it will schedule a completion with setTimeout. 140 | 141 | Usage: 142 | 143 | // asyncForEach is similar to: 144 | 145 | var i = 0; 146 | var array = [ ... ]; 147 | function nextElement() { 148 | if (i >= array.length) 149 | return; 150 | process(array[i++]); 151 | return nextElement; 152 | } 153 | this.$.taskQueue.scheduleWork(nextElement); 154 | */ 155 | @Element("fx-task-queue") 156 | class FxTaskQueue extends HTMLElement { 157 | number workLimit = 100; // ms 158 | number priority = 100; 159 | 160 | Promise scheduleWork(function fn -> optional fn); 161 | Promise asyncForEach(Array elements, function fn); 162 | void abort(); 163 | 164 | static void delayQueues(number priority = -1); 165 | static void resumeQueues(number priority = -1); 166 | } 167 | 168 | /* 169 | Declares a web worker to execute async work. Supports the following worker 170 | message protocol: 171 | 172 | { 173 | type: string, 174 | data: any, 175 | } 176 | 177 | The worker will be killed when the element is detached unless disconnect() 178 | is called. 179 | 180 | Note that all messages sent with send() expect a reply by default and will 181 | reject without a "timeout" error after the specified timeout unless you 182 | specify noreply = true. 183 | 184 | Usage: 185 | 186 | 187 | 192 | 193 | 194 | this.$.worker.send("doWork", [stuff]).then(function() { 195 | // ... done. 196 | }); 197 | */ 198 | @Element("fx-worker") 199 | @Event("message") 200 | @Event("error") 201 | class FxWorker extends HTMLElement { 202 | Worker worker; 203 | 204 | dictionary SendOptions { 205 | boolean noreply = false; 206 | number timeout = 100; 207 | Array transferList = []; 208 | } 209 | 210 | Promise send(string type, optional Object data, optional SendOptions options); 211 | void disconnect(); 212 | } 213 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fx-framework", 3 | "version": "0.0.0", 4 | "description": "A framework for rapidly building polymer apps.", 5 | "repository": { 6 | "type": "git", 7 | "url": "git@github.com:esprehn/fx-framework.git" 8 | }, 9 | "author": "Elliott Sprehn ", 10 | "license": "https://chromium.googlesource.com/chromium/src.git/+/master/LICENSE", 11 | "devDependencies": { 12 | "chai": "*", 13 | "karma": "^0.12.17", 14 | "karma-chrome-launcher": "^0.1.4", 15 | "karma-mocha": "^0.1.3", 16 | "mocha": ">=1.9" 17 | } 18 | } 19 | --------------------------------------------------------------------------------