• Stars
    star
    332
  • Rank 126,957 (Top 3 %)
  • Language
    JavaScript
  • License
    GNU Lesser Genera...
  • Created over 10 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Famous, the Meteor Way (with Reactive Blaze Templates/Views)

famous-views v1.x series Build Status

PROJECT STATUS: Please see http://forums.famous-views.org/t/with-much-regret-the-final-update/102/. Note that a few posts down, you'll see that some really awesome stuff is happening in the community (that I'm involved in too), so this project isn't dead yet. But I'll no longer be using official Famous and it might be a while until there is some news. Follow there for updates.


Oh look, it's a new major number. That means I can break the API :)

You're on the master branch, where work is in development for the totally unstable famous-views v1.x series, which works with famous v0.5 (mixed mode).

For the stable (but deprecated) famous-views v0.x, which works with famous v0.3.5, please see the v0 branch.

Forums.Famous-Views.Org and Join the chat at https://gitter.im/gadicc/meteor-famous-views

To learn the basics through an interactive tutorial with live, editable code, check out https://fview-lab2.meteor.com/gadicc.

API

The v1 series is a rewrite. A good opportunity for code househeeping. Code from v0 will be copied in and adapted on a per unit bases, after inspection and ideally tests.

Please read this README in it's entirety to understand what's going on :) Also, the v1.0.0 -- it's semver, we're bumping the major version to indicate an API change. Please don't draw any conclusions about being "production ready".

To learn the basics through an interactive tutorial with live editable code, check out https://fview-lab2.meteor.com/gadicc.

Quick start:

# Please check History.md on updates
meteor add gadicohen:famous gadicohen:famous-views

gadicohen:famous is a temporary package until our regular options are available again. It exports everything to a global famous var, e.g. famous.core.FamousEngine, etc. When we reach stable, we'll have a recommended pattern that works with all packages, which may involve wrapping famous-requiring-code with FView.ready() like last time, we'll see. But for now just use the globals.

The new markup structure looks like this:

<body>
  {{#Scene}}
    {{#Node}}
      {{#DOMElement}}
        <p>Yo!</p>
      {{/DOMElement}}
    {{/Node}}
  {{/Scene}}
</body>

Or a "full" example: (in Jade... use Jade!)

body
  +Scene
    +Node id="baseNode"
      +Node size="absolute: 100; renderSize" rotation="[1,1]"
        +DOMElement style="background: red" class="domEl" dir="rtl"
          p Howzit!
      +Node size="A:100; RS" rotation=reactiveRotationHelper
        +DOMElement
          p Shalom!

Scene

  • The only attribute supported is id

  • The scene attaches itself to the containing DOM element ('body' in the above example).

  • This element is given a 'fview-scene' class (which has appropriate CSS rules).

  • If attached to 'body', the relevant CSS is added for html and body to give you full control over the browser window.

  • For any other element (e.g. 'div'), you should set the appropriate width, height, margin and padding as appropriate. If the element has no id, famous-Views will map it to the node's id.

Node

Supported non-reactive attributes:

  • id - retrievable via FView.byId(x)
  • _onRender shortcut -- see below

Supported reactive attributes:

  • size - adds fview.size instance and sets size (see below for the format)
  • position / align / mountPoint / origin / rotation / scale - see below

Sizing

See http://famous.org/learn/sizing.html for the sizing types. We believe in minimal typing, so we have a proprietary string format that looks as follows (spaces are optional, names may be shortened and case is insensitive, so the following two groups are equivalent):

size="50%, -10"
size="proportional: 0.5; differential: -10"
size="P:0.5; D:-10"

size="150, RS, 50% - 10"
size="absolute: 150; renderSize; relative: 0.5,-10"
size="A:150; RS; R:0.5,-10"

The second group would do the following in famous:

var size = fview.size = new Size(node);
size.setMode(Node.ABSOLUTE_SIZE, Node.RENDER_SIZE, Node.RELATIVE_SIZE)
size.setAbsolute(150);
size.setProportional(undefined, undefined, 0.5);
size.setDifferential(undefined, undefined, -10);

The "natural" sizing works like this: "x, y, z" where these can be (spaces optional):

  • renderSize or rs (case insensitive) --> RENDER_SIZE
  • 100 (a number) --> ABSOLUTE_SIZE
  • 50% (a number + percent sign) --> proportional (via RENDER_SIZE)
  • +10 (+/- a number) --> differtial (via RENDER_SIZE)
  • 20% - 10 --> RENDER_SIZE

Everything else (including position, rotation, etc)

String decoding similar to famous-views 0.x, e.g. position="[100,100]", JSON and some other stuff. You should return an exact value (e.g. an Array of Numbers) from reactive helpers.

Notes:

  • Numbers are passed as is. In v0 we took degrees from helpers and converted them to radians to pass to Famous. This may or may not happen in v1 (i.e. API is still unstable). Probably we'll have a rotationDeg shortcut, etc.

  • We only instantiate a new component as fview.position etc if a transition is specified.

For animations, you can return a special object ala famous-views v0:

Template.body.helpers({
  reactiveRotate: function() {
    return {
      value: [0, 1],
      transition: { duration: 1000, curve: 'inBounce' }
      halt: true,                   // optional (TODO)
      callback: function() { ... }  // optional
    };
  }
});

To keep switching between two values, we provide a shortcut to infinity:

+Node rotation='{ "value1": [0,-3.14], "value2": [0,3.14], "transition": { "duration": 1000 } }'

To reset the loop on each iteration (for a continuous animation "in the same direction", given appropriate values) add: _loopFromBeginning: true.

You can also simply manipulate the fview directly and return '__FVIEW_SKIP__', e.g.:

Template.body.helpers({
  reactiveRotate: function() {
    FView.current().node.setRotation(x,y,z);
    return '__FVIEW_SKIP__';
  },
  reactiveRotate2: function() {
    var fview = FView.current();
    if (!fview.rotate)
      fview.rotate = new famous.components.Rotation(fview.node);
    fview.rotate.set(1,2,3, transition, callback);
    fview.rotate.setX(1, transition, callback);
    return '__FVIEW_SKIP__';
  }
});

Special Attributes:

_onRender:

Specify the name (by string) of a helper function that we should run after adding the node to the Scene Graph.

body
  +Node _onRender="renderFunc" // note, String name
Template.body.helpers({
  renderFunc: function() {
    // this = fview
  }
});

DOMElement

This is a component that is added to the enclosing node, it's not a real node on it's own, it simply attaches a DOMElement component to the enclosing node, and the augments that node's fview with:

  • fview.domElement - the DOMElement instance
  • fview.updateSize() - forces an update for RENDER_SIZE'd nodes
  • fview.updateSizeDeferred() - as above, but deferred (useful for reactive helpers)

Template attributes:

  • style="background: red; color: white" (reactive)
  • class="class1 class2 etc" (reactive)
  • dir="rtl" and any other attribute (reactive)
  • tagName like in famous -- NOT IMPLEMENTED YET (TODO)
  • watchSize like in v0 -- NOT IMPLEMENTED YET (TODO)

The {{>Surface template="x"}} format is gone, just put {{>x}} inside.

If using RENDER_SIZE, you have to let us know if you do anything that could change the size of the rendered content, using one of the Methods above. Here's an example for a reactive helper:

Template.body.helpers({
  something: function() {
    FView.current().updateSizeDeferred();
    return variableSizedStuff;
  }
});

Others

Mesh, Camera, PointLight are all very simple wrappers and work how you'd expect. See the live demos for some examples.

  • Mesh geometry='Torus' baseColor='white, 0.5' glossiness='white; 500'

Components in general with attributes ending with [cC]olor, i.e. color, baseColor, can parse values like "white", "white, 0.2" (for opacity 0.2), "#ffffff".

famousEach

Use this instead of Meteor's built-in #each inside the Scene graph. This is required to maintain ordering and allows wrapped code to capitalize on ordered insertions/removals/reorders.

FView (global)

  • FView.byId(id) - gets the fview from e.g. {{#Node id="myNode"}}etc{{/Node}}
  • FView.from(viewOrTplorEl) - gets the fview from a Blaze View, a Template Instance or a DOM element (of the regular, non-famous variety)
  • FView.current() - great new shortcut for inside helpers, Meteor events, template/view autoruns and some callbacks. Uses Blaze.currentView internally.

FV (global)

jQuery inspired short-cut to get the fview, e.g.

  • FV(fview), FV('#id'), FV('.class'), FV('Node') -- multiple selectors soon
  • FV(fview).children(selector), closest(), parents(), parent(), find(), siblings(), eq(), each()
  • Chainable (but not so many methods yet), jQuery like (so use FV(something)[0] to get the real fview and not an FV-wrapped array), etc

You can also set up onRender events for nodes in a class, e.g. (included by default):

FView.defineClass('center', {
  onRender: function() {
    this.node.setMountPoint(0.5, 0.5, 0.5);
    this.node.setAlign(0.5, 0.5, 0.5);
    this.node.setOrigin(0.5, 0.5, 0.5);
  }
});

Which means you can:

+Node class="center"
  +Node class="center"

etc.

fview (node/etc instance)

Properties

  • fview.id
  • fview.node - the node instance
  • fview.components - dictionary of data for added components
  • fview._class - class data
  • fview.* - misc other stuff depending on the node type/class

Methods

  • fview.autorun(func) -- just like tplOrView.autorun in Meteor/Blaze except this in the callback will be the fview; automatically removed when node is destroyed.

Wrap your Own

Just as with v0, famous-views is primarily a low-level wrapper around Famous, to make it fit in naturally with Meteor. We don't aim to provide a comprehensive library of community components, instead, we realy on other developers to provide fview-* plugin packages. It's not so hard to do, and we'll have some example patterns for v1 available soon.

But what about stuff you don't want to publish, or isn't already published? How can you wrap simple things? Well, like this:

FView.wrap('Node', famous.core.Node);  // silly example, already included
FView.wrapComponent('Mesh', famous.webglRenderables.Mesh);

This will give you {{#Node}} and {{#Mesh}} helpers to use in your templates. Adding children / attaching components all work as you'd expect. Admittedly it's not always this simple, but a 3rd parameter, options can provide a dictionary of overrides to adapt as necessary. You may find some more useful examples here:

https://github.com/gadicc/meteor-famous-views/tree/master/lib/wrappers

Logging

Package['jag:pince'].Logger.setLevel('famous-views', 'info');

Levels are: trace, debug, info, warn, error

In a later release I'll enable to change this before load, for those who hate anything on console :)

Events

Might add something to do this in a Meteor way again. For now, either set these up famous-style _onRender (in famous style, see their docs) or do something like this:

<template name="outer">
  {{#DOMElement}}
    {{>inner}}
  {{/DOMElement}}
</template>

<template name="inner">
  <!-- NB: Critical to have one element in here to receive the event -->
  <!-- depending on your needs, maybe style="width: 100%; height: 100%" -->
  <div>Blah blah blah</div>
</template>
Template.inner.events({
  'click': function(event, templateInstance) {
    var fview = FView.current();
    // `this` is data context; regular Meteor event, etc.
  }
});

What's missing / TODO / Roadmap

  • Defer/tracker override
  • Ability to remove/destroy templates :)
  • famousEach, famousIf, etc
  • Events in a Meteor way again?
  • Loads of other stuff from v0... request them and I'll prioritize

Differences from v0

Besides the underlying Famous API and how we deal with it:

  • In v0 we could use famous-views stuff inline {{#Surface}}...{{/Surface}} and via inclusion {{>Surface template="mySurface"}}. The latter enabled us to use life cycle callbacks and events, but was a big source of confusion amongst users, and stifled fast development but requiring a lot of extraneous subtemplating. In the new version we just use _onRender and _eventMap attributes, provided from the enclosing Templates single helper. Feedback welcome. You can still use regular inclusion {{>template}} like usual.

  • In v0 a MeteorFamousView was (usually) a kind of renderNode too. In v1 we maintain a separatation, we maintain our own tree (like we had to in v0 too) but add famous nodes directly to the scene graph.

More Repositories

1

node-yahoo-finance2

Unofficial API for Yahoo Finance
HTML
381
star
2

meteor-hmr

Hot Module Replacement for Meteor; in your app, with react, with build plugins
JavaScript
142
star
3

meteor-sitemaps

Quickly create dynamic ("real-time") sitemaps using your own functions.
JavaScript
87
star
4

meteor-headers

Access HTTP headers on both server and client. Client IP with proxy support.
JavaScript
61
star
5

meteor-blaze-react-component

<Blaze template="itemsList" items={items} />
JavaScript
61
star
6

meteor-messageformat

MessageFormat i18n support for Meteor, with reactive templates
JavaScript
54
star
7

meteor-reactive-window

Reactive functions for window properties; width, scroll, etc
JavaScript
29
star
8

meteor-phantomjs

Smart package to ensure PhantomJS is automatically installed
JavaScript
25
star
9

fview-flex

IjzerenHein's famous-flex for famous-views (Meteor)
JavaScript
23
star
10

meteor-blaze-virtual-dom

An experiment to use Blaze with a virtual dom
JavaScript
16
star
11

mongodb-rest-relay

Relay mongodb queries over HTTP REST. Great for Edge.
TypeScript
14
star
12

meteor-robots.txt

Serves a robot.txt which can be modified programatically
JavaScript
10
star
13

espruino-gc-meteor

JavaScript
10
star
14

fview-lab

Real-time playground for meteor famous-views
JavaScript
9
star
15

famin

JavaScript
9
star
16

meteor-usermap

A map of Meteor users
JavaScript
8
star
17

node-hosts-so-easy

Safe, parallel API for manipulating /etc/hosts.
JavaScript
8
star
18

redalert

Hackathon related stuff, mostly Tzeva Adom related
JavaScript
6
star
19

meteor-extensions

Add support for extensions (hooks, plugins) to your app
JavaScript
6
star
20

phantomjs-remote

Run phantomjs on a remote server (e.g. if no binary is available locally)
JavaScript
5
star
21

magickli

open source magick stuff....
TypeScript
5
star
22

wmd

JavaScript
5
star
23

meteor-doingthiswith

Anybody doing this [technology/framework/sitetype] with Meteor?
JavaScript
5
star
24

fview-quickstart

Fresh meteor project using quickstart instructions from famous-views
CSS
4
star
25

meteor-famous

Temporary package for Famo.us Mixed Mode v0.5.0
JavaScript
4
star
26

meteor-prism

Prism Syntax Highlighter, integrated with Meteor
JavaScript
4
star
27

fview-lagometer

IjzerenHein's lagometer packaged for famous-views
JavaScript
4
star
28

meteor-spiderable-remote

Like spiderable, but runs phantomjs via phantomjs_remote
JavaScript
4
star
29

fview-sizeconstraint

set renderable scale, padding, max-size, min-size and aspect-ratio
HTML
4
star
30

mink

Mink - Meteor integration for INK File Picker
JavaScript
3
star
31

fview-timbre

Famous Timbre demo using famous-views
JavaScript
3
star
32

fview-demo

Demo of simple app using famous-views
CoffeeScript
2
star
33

meetup-fview-london

Slides for Meteor London meetup 2015-06-25
HTML
2
star
34

meteor-rest-test

Quick and dirty code to make HTTP.call's of different types and check request/response
JavaScript
2
star
35

meteor-accounts-merge

Let user login to and add multiple services to one account
JavaScript
2
star
36

meteor-snippets

Code snippets with highlighting and lang conversion
JavaScript
2
star
37

meteor-cross-domain-login

User remains logged in on same site across multiple domains
JavaScript
2
star
38

async-composable-tasks

Composable async tasks designed for await/sync and arrow functions, with progress and parallelism.
JavaScript
2
star
39

meteor-jquery2

jQuery 2.x packaged for Meteor
JavaScript
1
star
40

meteor-modules

Minimalist require support, with glslify hack.
JavaScript
1
star
41

meteor-react-container-efficiency

One autorun vs isolated autoruns in react
JavaScript
1
star
42

meteor-modal-bs3ui

bootstrap 3 modals, the Meteor way (for Meteor UI)
JavaScript
1
star
43

discourse2

Complete Discourse API, strongly typed
TypeScript
1
star
44

rtr-utils

Helpful utilities for react-three-render
JavaScript
1
star
45

meetup-fview-tlv

Meteor TLV Meetup 2015-06-14
HTML
1
star
46

meteor-mongo-stream

Live streaming of (recorder) streams (stdout/stderr/anything) to the browser
JavaScript
1
star
47

repro-ranjeev

https://forums.meteor.com/t/how-to-make-blaze-templates-reactive/21027
JavaScript
1
star
48

esphome-render

Live editor with realtime previews of esphome display component
TypeScript
1
star
49

meteor-jade-client

Wrapper for mquandalle:jade to use client-side
JavaScript
1
star
50

contributors-svg

Code for Contributors SVG service
JavaScript
1
star
51

meteor-json5

Meteor wrapper for json5 npm package
JavaScript
1
star
52

blaze-content

Minimal reproduction showing that content overrides .content in current context
JavaScript
1
star
53

redux-router-state

Store router state in Redux and route via redux
JavaScript
1
star
54

squid-ssl-zero

Zero-config squid caching proxy with SSL intercept (sslbump)
Shell
1
star
55

shadowlang

TypeScript
1
star
56

meetup-fview-ottawa

HTML
1
star
57

fetch-mock-cache

Caching mock fetch implementation for all JS runtimes and frameworks.
TypeScript
1
star