Exemplo n.º 1
0
        createRuleStr: function (selector, rule) {
            var props = '';
            each(rule, function (value, key) {
                props += key + ':' + value + ';';
            });

            return selector + '{' + props + '}';
        },
Exemplo n.º 2
0
        update: function (state) {
            if (state === this.lastAppState) {
                return;
            }

            var dynamicCss = this.entities.getAllComponentsOfType('css');
            each(dynamicCss, this.updateDynamicCss, this, [state]);

            this.lastAppState = state;
        },
Exemplo n.º 3
0
        update: function (currentAppState) {
            if (currentAppState === this.lastState) {
                return;
            }

            var stateComponents = this.entities.getAllComponentsOfType('globalToLocal');

            each(stateComponents, this.updateEntity, this, [currentAppState]);

            this.lastState = currentAppState;
        },
Exemplo n.º 4
0
        prepare: function (raw, result, selector) {
            each(raw, function (value, key) {
                if (value && typeof value === 'object') {
                    this.prepare(value, result, this.combineSelector(selector, key));
                    return;
                }

                result[selector] = result[selector] || {};
                result[selector][key] = value;
            }, this);

            return result;
        },
Exemplo n.º 5
0
        updateEntity: function (globalToLocal, entityId, appState) {
            var newState = this.entities.getComponentData(entityId, 'state') || {};

            if (utils.isFunction(globalToLocal)) {
                newState = globalToLocal(appState, newState);

            } else {
                each(globalToLocal, function (localKey, globalPath) {
                    newState[localKey] = immutable.find(appState, globalPath);
                });
            }

            this.entities.setComponent(entityId, 'state', newState);
        }
Exemplo n.º 6
0
    }).whenBrewed(function () {
        this.state = immutable.fromJS({
            route: '#/',
            todos: []
        });

        this.ui = UI.brew({
            messages: this.messages,
        });

        each([
            StorageController.brew(),
            TodoController.brew(),
        ], this.wireUp, this);
    });
Exemplo n.º 7
0
        wireUp: function (controller) {
            if (!controller) {
                throw 'Invalid input: Empty value';
            }

            if (!controller.messages) {
                throw 'Invalid input: Message map missing';
            }

            each(controller.messages, function (fnName, message) {
                this.messages.on(message, function (data) {
                    var fn = controller[fnName];
                    this.state = fn.call(controller, this.state, data);
                }, this);
            }, this);
        },
Exemplo n.º 8
0
            renderer: function (ctx) {
                var h = ctx.h;
                var todos =  ctx.state.val('todos');
                var hasTodos = todos.length > 0;
                var allCompleted = ctx.state.val('allCompleted');

                return h('.main', {
                    className: hasTodos ? '' : 'hidden'
                }, [
                    h('input.toggle-all', {
                        type: 'checkbox',
                        checked: allCompleted,
                    }),

                    h('label', {
                        htmlFor: 'toggle-all'
                    }, 'Mark all as complete'),

                    h('ul.todo-list', null, each(todos, ctx.placeholder, ctx))
                ]);
            },
Exemplo n.º 9
0
 setRules: function (rules) {
     each(this.prepare(rules, {}, ''), this.setRule, this);
 },