Git Product home page Git Product logo

way.js's Introduction

way.js

Gitter

Simple, lightweight, persistent, framework-agnostic two-way databinding Javascript library.
With no to little JS code to write. And no dependencies.

Demo
Codepen
jsFiddle

Buy us coffee: Gittip
Follow us on Twitter: @way_js

The following documentation is also available in Chinese (credits: @wuyunjiang).

Quick start

Declare an HTML element with some tags.

  <form way-data="myFormData" way-persistent="true">
  	<input type="text" name="name">
  	<input type="text" name="age">
  	<input type="text" name="gender">
  </form>

  Name: <span way-data="myFormData.name"></span>

Boom. Now every change in the form will be stored in-memory. The bound span's html will be changed on the fly. And the bound data will be persistent, meaning your HTML will be populated with your data on page reloads.

Enough talk, see it in action.

Installation

[Step 1] Include the library to your page.

1.a. via NPM

npm install way-js

then

import 'way-js';

1.b. or

<script src="dist/way.js"></script>

[Step 2] There is no step 2. You are good to go.

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to way-, as in way-data="". Set these options to the elements that have to be bound.

Name Type Default Description
data string null Allows to define the dot separated path where the data will be stored. Can include arrays. When used on a form, a json variable made of all the included inputs with a [name] attribute will be created and stored in the specified storage. Pass the "__all__" path to access all way.js' data.
default string null A link to a default data to set on an element, in case there is no bound value.
persistent boolean true Allows to store the data to localStorage everytime the bound data changes.
readonly boolean false Prevents the element changes from resetting the bound value.
writeonly Boolean false Prevents the element from getting changed when the bound value changes.
json boolean false Returns pretty-printed json data to its DOM element.
html boolean false Declares whether the data attributed to an element should be parsed as HTML or not.
pick array null A comma separated list of values to pick (in forms only) to sync with the storage. By default, all form inputs are synced.
omit array null A comma separated list of values (in forms only) to not sync with the storage. By default, no form input is omitted.

Some examples:

<form way-data="some.form" way-pick="some,properties,that,can.be.nested">
<form way-data="some.form" way-omit="dont,want.those">
<img way-data="some.image" way-default="http://upload.wikimedia.org/wikipedia/en/a/a6/Bender_Rodriguez.png">
<pre way-data="some.json" way-json="true"></pre>

Scopes

You can set scopes to your DOM elements' data.

[way-scope] attribute
Passing this attribute to an element will point all its children's "way-data" attributes to this scope. Scopes can be nested.

way.set("someScope", { with: { something: "hello" }})
<div way-scope="someScope">
  <div way-scope="with">
    <div way-data="something"></div> <!-- Will render "hello" -->
  </div>
</div>

[way-scope-break] attribute
Breaks a scope chain. All the child elements of this one will have no scope set.

way.set("someScope", { with: { something: "hello" }})
<div way-scope="someScope">
  <div way-scope-break="true">
    <div way-data="someScope.with.something"></div> <!-- Will render "hello" -->
  </div>
</div>

scope() method
Returns the scope of a given DOM element

<div way-scope="someScope">
  <div way-scope="with">
    <div way-data="something" id="someDIV"></div>
  </div>
</div>
way.dom("#someDIV").scope()  
>> "someScope.with"

Repeats

Duplicates a DOM element for each of the values it can loop through in a way.js' passed data.
Notes:

  • Repeat blocks automatically set the appropriate scope to their child elements.
  • On each loop, "$$key" corresponds to the key of the current element looped.

Having this:

way.set("some.list", [
	{name:"Pierre"},
	{name:"Paul"},
	{name:"Jacques"}
]);
<div way-repeat="some.list">
	$$key - <span way-data="name"></span>
</div>

Will render that:

<div way-scope="some.list">
  <div way-scope="0">
    0 - <span way-data="name">Pierre</span>
  </div>
  <div way-scope="1">
    1 - <span way-data="name">Paul</span>
  </div>
  <div way-scope="2">
    2 - <span way-data="name">Jacques</span>
  </div>
</div>

Transforms

Transforms the displayed data bound to your DOM elements.

[way-transform] attribute
Pass transform functions by name. Add multiple transforms by separating them with the "|" symbol.
In case of conflicts between transforms, the last mentionned transform wins.
Some pre-build transforms [PR welcome for more!]

Name Description Example
uppercase Sets a string to uppercase "hello" becomes "HELLO"
lowercase Sets a string to lowercase "HELLO" becomes "hello"
reverse Reverses a string "hello" becomes "olleh"
way.set("someData", "hello")
<div way-data="someData" way-transform="uppercase"></div>
<!-- Renders "HELLO" -->

registerTransform(name, transform) method
Adds a new transform.

way.set("someData", "hello");
way.registerTransform("lolify", function(data) {
  return data + " lol";
});
<div way-data="someData" way-transform="lolify|uppercase"></div>
<!-- Renders "HELLO LOL" -->

Helper elements

Allows to perform simple tasks on your way.js' data with a click.

Attribute Description
way-action-remove Removes a way data
way-action-push if provided with an array, pushes an null value to it

Example:

way.set("some.list", ["I", "am", "list"]);
<div id="clickToRemove" way-action-remove="some.list.2"></div>
<div id="clickToPush" way-action-push="some.list"></div>
$("#clickToRemove").click();
$("#clickToPush").click();
way.get("some.list");
>> ["I", "am", null]

Helper classes

For images only way.js adds classes to your DOM elements to easily detect load / error / success statuses with the data they get passed.

Class Description
way-loading When an image is getting downloaded to a DOM element
way-error When no image is returned from the URL provided
way-success When... Well, you got it.
way.set("image.url", "somethingThatsNotAnImageURL");
<img way-data="image.url">
<!-- Gets a class ".way-error" attributed -->

Methods

Everything should be done for you from the HTML tags. But if necessary, you can also use helper functions to interact with your stored data and DOM elements.

Notes:

  • [element] refers to the CSS selector of a DOM element.
  • [options] is optional. By default, options are read from the HTML tags of the elements. But you can overwrite them, by passing this parameter.

DOM methods

way.dom(element).toStorage(options)
Stores the element's value to the in-store memory.

way.dom("#someForm").toStorage()

way.dom(element).fromStorage(options)
Sets the element's value from the stored one.

way.dom("#someForm").fromStorage()

way.dom(element).toJSON(options)
Returns a JSON with the parsed data of the input (particularly handy for forms).

way.dom("#someForm").toJSON()

>> {
		its: "values",
		serialized: {
			in: "a json"
		}
	}

way.dom(element).fromJSON(data, options)
Sets the element's value from any data (in json).

way.dom("#someForm").fromJSON({name:"John Doe"})

way.dom(element).getValue()
Returns a structured JSON containing the value of the DOM element.

way.dom("#someForm").getValue()

way.dom(element).setValue(value, options)
Sets the element's value from any data (in json).

way.dom("#someForm").setValue({name:"John Doe"})

way.dom(element).setDefault(force)
Sets the default value of an element. By default, only the DOM element gets its value set to the default value. Its bound value in the datastore in unchanged. Pass a [force] parameter if you need to force setting in-memory value of this data to the element's default value.

way.dom("#someForm").setDefault()

way.setDefaults(force)
Sets all the default values of bound DOM elements.

way.setDefaults()

way.dom(element).getOptions()
Returns the list of the ["way-"] options attributed to a DOM element.

way.dom("#someForm").getOptions()

Data methods

way.get(selector)
Returns the value of the data stored under a given pathname.

way.get("some.path");
>> "bonjour"

way.set(selector, value, options)
Saves the data in memory under the specified pathname.

way.set("some.path", "bonjour!");

way.remove(selector, options)
Removes the data stored under a given pathname.

way.remove("some.path");
way.get("some.path");
>> undefined

way.clear(options)
Clears all the data

way.clear();
way.get();
>> {}

localStorage methods

way.backup()
Stores the data saved in way.js' datastore to localStorage.

way.backup();

way.restore()
Restores the data saved in localStorage. Called on $(document).ready by default (can be changed with global options).

way.restore();

Binding methods

way.registerBindings()
Triggers a scan of the DOM to find and save the elements with the [way-data] attribute, that will be bound with some data.

way.registerBindings()

way.updateBindings(selector)
Sets the value of all the DOM elements binded to a data selector with their values in way.js' datastore. If omitted, all (excluding write-only's and omitted) DOM elements with a "way-data=" attribute will be refreshed.

way.updateBindings("formData.name")

Repeat methods

way.registerRepeats()
Triggers a scan of the DOM to find and save the elements with the [way-repeat] attribute, that will be bound with some data.

way.registerRepeats()

way.updateRepeats(selector)
Triggers a refresh of the repeat elements with their respective data.

way.updateRepeats("somethingToBeLooped")

Watcher methods

way.watch(selector, callback[value])
Watches changes of a given value.

way.watch("some.data", function(value) {
	console.log("Data has been updated to value: " + value);
});

way.watchAll(callback[selector, value])
Watches all changes in way.js' datastore.

way.watchAll(function(selector, value) {
	console.log("The data " + selector + " has been changed.", value);
});

Global options

way.options.persistent (Boolean)
Sets whether or not data will be restored from localStorage on document.ready (true by default).

way.options.persistent = true

way.options.timeoutInput (Number)
Number of milliseconds of the timeout between keypresses on bound elements to store their values to the datastore (50 by default).

way.options.timeoutInput = 50

way.options.timeoutDOM (Number)
Number of milliseconds of the timeout between scans of the DOM to list bound elements on each DOM change (500 by default).

way.options.timeoutDOM = 500

To do

  • document a bit more the code
  • test
  • enjoy

Integrations

  • [Meteor] To be coming

Contribute

  • Fork & pull request.
  • If you planning add some feature please create issue before.

Otherwise changes will be rejected.

Licence

The MIT License

Copyright (c) 2014 Gwendall Esnault [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

way.js's People

Contributors

gitter-badger avatar gwendall avatar justim avatar ryan-scott-dev avatar woodworker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

way.js's Issues

toJSON & fromJSON not working as advertised

I'm trying to bind the form to a json-object that is retrieved from a database, but it gives me errors.

So I tried to use the toJSON function to get an object that would have the correct format, to feed it back into the fromJSON function, but the toJSON function doesn't give me a JSON object as advertised in the documentation, but the html-code of the form.

Am I reading docs wrong? How can I bind data from a database to the form and the other way around?

Keep up the good work.

Can I binding data to a.href or other attribute

How can I replace text 'link-url' by data-binding?

way.set("link-text", "this is a link");
way.set("link-url", "http://this.is.a.url/");
<a href="link-url" way-data="link-text"></a>

I expects:

<a href="http://this.is.a.url" way-data="link-text">this is a link</a>

but actually it renders

<a href="link-url" way-data="link-text">this is a link</a>

null appearing in text fields

I have some props in my object that are string (in the json text string) but type being reported as object. and contain null values. When bound to a textbox the word 'null' appears. Shouldn't it handle this and instead use an empty string when binding with textboxes?

I got around this by cleaning up the object prior to loading it into way.js using (jquery):

for (var property in obj) {
if (obj.hasOwnProperty(property) && $.isEmptyObject(obj[property]))
   obj[property] = '';
}
way.set("scope", obj);

I'm coming from angular data-binding and wanted a lightweight data-binding solution for my non-angular projects and this is exactly what i needed. Great work!

Free commas

Commas seem to be added after every way-action-push; is this something we could toggle on or off? It's visible in the demo.

Cheers!

Knockout

I'd love to know how this compares to Knockout which is pretty much just for two-way data-binding too (without the persistence).

watch method has a bug

Line 68 and 69, ’this._watchers[item]‘ was wrong, please change to 'self._watchers[item]'.

Doesn't work while loading a template via EJS

Hi. The lib seems to work pretty wellbut I can't make it work when I load a template and put on the DOM

Reading the documentation, seems I need to call
way.registerBindings();

after load the HTML into the DIV

If I check the attributes in the console, all the attributes way-readonly="false", ... seems to be well configured but the divs are not automatically updated on the DOM changes.

If I put the HTML with no templates and I didn't use the registerBindings all seems to work well.

It's anything else needed to make this lib works after injecting HTML into a DIV?

Kind regards

Chrome autocomplete doesn't work

It looks like when the chrome autocomplete fills out an input field, the associated way model is not updated. Is there a way around this, such as reloading/refreshing the way model and grab all the input values again?

What event to watch for binding ?

hello there ! First, nice little helper lib you have here.

Then i have a little question ... i have an input text ( part of a way.repeat() ) that i populate/change value programmatically ... But it seems 'Way' doesn't update the json values when the input is updated.

What kind of event are you watching to trigger the refresh ? SO that i can trigger it myself whenever the value is updated !

Thanx a bunch

Logo >> undefined

If someone with graphic design chops wants to help, would be cool to have a logo for this library!

unshift method needed

There is _json.unshift existed, but no way.unshift provided.
I my project, I need one ul list with data bound, and new li object should be put on the top.
I tried reverse, but it didn't work on repeat data attribut.
Thanks a lot.

Program Specific issue (Slow response)

Example

                    <div class="form-group">
                        <label class="col-sm-3">Quiz Title</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="QuizTitle" placeholder="Quiz Title" autocomplete="off">
                        </div>
                        <label class="col-sm-3">Quiz Description</label>
                        <div class="col-sm-9">

                            <textarea class="form-control" name="QuizDescription" placeholder="Quiz Description" autocomplete="off" rows="3"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3">Quiz Picture</label>
                        <div class="col-sm-9">

                            <input type="text" class="form-control" name="picture" placeholder="Enter an image's URL to see magic"
                                autocomplete="off">
                            <img class="img-responsive" way-data="formData.picture"
                                way-default="http://creditworksusa.com/wp-content/uploads/2014/03/facebook-default-profile-photo.jpg">
                        </div>
                    </div>

                    <div class="single_result_wrapper" way-repeat="formData.Results" style="padding: 0px;">
                        <label>Results</label>
                        <div>
                            <div class="item-entry">
                                <input type="text" class="form-control" placeholder="Result Title"
                                    way-data="title" way-persistent>
                            </div>
                            <div class="single_result_inner">
                                <div class="result_image">
                                    <div class="upload_icon"></div>
                                    <div class="upload_text">Click to add Photo/Video</div>
                                </div>
                            </div>
                            <a href="#" way-action-remove="formData.Results.$$key" way-persistent>Remove</a>
                        </div>
                    </div>
                    <div class="form-group">

                        <div class="col-sm-9">
                            <a href="#" way-action-push="formData.Results" style="position: relative; top: 5px; left: 12px;">Add a Result</a>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3">Questions</label>
                        <div class="col-sm-9">
                            <a href="#" way-action-push="formData.Questions" style="position: relative; top: 5px; left: 12px;">Add Questions</a>
                        </div>
                    </div>
                    <div class="form-group" way-repeat="formData.Questions" style="padding: 0px;">
                        <label class="col-sm-3"></label>
                        <div class="col-sm-9">
                            <div class="item-entry">
                                <input type="text" class="form-control" placeholder="Question Title"
                                    way-data="title" way-persistent>
                            </div>


                            <label class="col-sm-3">Answers</label>
                            <div class="col-sm-9">
                                <a href="#" way-action-push="formData.Answers" style="position: relative; top: 5px; left: 12px;">Add an Answer</a>
                            </div>

                            <div way-repeat="formData.Answers" style="padding: 0px;">
                                <label class="col-sm-3"></label>
                                <div class="col-sm-9">
                                    <div class="item-entry">
                                        <input type="text" class="form-control" placeholder="Answer Title"
                                            way-data="title" way-persistent>


                                        <div way-scope-break="true" style="padding: 8px 0px 0px 8px; border-top: rgba(0, 0, 0, .1) solid thin; margin-top: 8px;">
                                            <div way-repeat="formData.Results">
                                                <span way-data="title"></span>
                                            </div>


                                        </div>
                                        <div way-repeat="formData.Results">

                                            <span style="margin-left: 10px; font-weight: bold;">Weightage</span>
                                            <label>
                                                <input type="radio" way-data="level" value="0" checked="checked">0

                                            </label>
                                            <label>
                                                <input type="radio" way-data="level" value=".25">.25

                                            </label>
                                            <label>
                                                <input type="radio" way-data="level" value=".5">.5

                                            </label>
                                            <label>
                                                <input type="radio" way-data="level" value=".75">.75

                                            </label>
                                            <label>
                                                <input type="radio" way-data="level" value="1">1

                                            </label>
                                        </div>
                                    </div>

                                </div>


                                <a href="#" way-action-remove="formData.Answers.$$key" way-persistent>Remove</a>
                            </div>

                        </div>
                    </div>
            </div>

        </div>
    </div>

    <div class="col-sm-6 col-fixed">

        <div class="alert bg-warning">
            This is the data stored in way.js

        <div class="btn btn-sm btn-default pull-right" style="position: relative; top: -5px;" way-clear way-persistent>
            Clear data      
        </div>
        </div>
        <pre way-data="__all__" way-json="true" way-default="{}"></pre>
    </div>
</div>

So this is code I am using in body tag so when I add new answer in Question it takes so much time. No idea why? Page become unresponsive sometimes.
image

The sample doesn't work the same between browsers

I run the sample code at windows. The browsers i use are firefox31 and chrome35.0.1916.153.

The sample can get the expected json result in chrome for the option "skills" while in firefox it just
come out to the wrong place, just the same level as "formData" in json result.

Not sure what happened but please have a check, thanks.

CMD + Backspace

CMD + Backspace doesn't trigger data change in your demo. OSX 10.9.4, Chromium 36.0.1985.125

How to bind an element attribute or className ?

is there any kind of method binding element's attribute or className?

for example :

<div way-attr-data="scope.hidden" way-attr-name="hidden" id="d" ></div>

when i set scope.hidden as true , element d.hidden= true;

When restored data, watch has not been emitted

I have some data as follow:

{
  formData: {
    foo: 'bar'
  }
}

and then I watch the property foo:

way.watch('formData.foo', function (foo) {
  //my code...
});

The watch has not been emitted after loaded page.
I found that the watchAll could be emitted, but I only want to watch a specific property, what should I do?

About "timeoutInput" questions

When I realized "check all" by jquery, some bad things happened, way.js unable to detect changes in the value of, so I can manually trigger "change" events, but "setTimeout" led to erroneous results.
My code:

<!--html-->
<input type="checkbox" data-checkAll="a1"/> Check All

<input type="checkbox" value="1" data-checkall-bind="a1" way-data="ids.1">
<input type="checkbox" value="2" data-checkall-bind="a1" way-data="ids.2">
<input type="checkbox" value="3" data-checkall-bind="a1" way-data="ids.3">

<!--javascript-->
<script>
    $("input[type=checkbox][data-checkAll]").on('click',function(e){
        var p = $(this).attr('data-checkAll');
        var checked = $(this).prop('checked');
        var items = $("input[type=checkbox][data-checkAll-bind='"+p+"']");
        items.prop('checked',checked);

        var evt = document.createEvent('Event');
        evt.initEvent('change',true,true);

        items.each(function(){
            this.dispatchEvent(evt);
        });
    });    
</script>

<!--console result-->
way.get('ids');//{3:3}

As you can see, I hope the result is "{1:1,2:2,3:3}".

Then I look at your code, found to be caused here:

var eventInputChange = function(e) {
    if (timeoutInput) { clearTimeout(timeoutInput); }
    timeoutInput = setTimeout(function() {
        var element = w.dom(e.target).get(0);
        way.dom(element).toStorage();
    }, way.options.timeout);
}

Because I was using code triggered, event interval is very, very small, so "clearTimeout" is continuously invoked.

Then I changed the code,look here:
keepeye@10047f5

I don't know if it will bring unexpected problems,but it works for me.

Git tags for the library versions

Hi! Could you add a tag of the current version 0.1.0 in the repository? It is necessary for proper work of the Bower.
Thanks in advance!

nojquery几个错误的地方

  1. 数组html需要join
w.dom(wrapper).html(items);

=>

w.dom(wrapper).html(items.join(""));
  1. 转换类型
return str ? str.replace(/&/g, "&amp;")....

=>

return str ? (str + "").replace(/&/g, "&amp;")...

IE Support?

I can't seem to see it mentioned anywhere as to whether or not any versions of IE are supported, and I know how painful it can be to get it to do so! Just thought I'd check first :) Cheers

Framework agnostic?

How can you label this as framework agnostic when it includes and depends on jQuery? That warning should be in the same line as the "include this one file" happy-doc in the README.

update server

Hey,

What is the correct way to update the server when data is updated?
for example, I have an array of notifications with "dismiss" button that removes the item.
what is the right way to let the server know that the item is dismissed?

Very nice work!

Bnaya

Design decision question

Was there any reason you chose way-data as opposed to the html5 data-way variation? The latter of which would make it possible to access information through element.dataset.way.*

way-data save multiple options of select

Dear, as I can be stored in the "way-data" a set of elements? I need to store in a select multiple options.???

generates the following structure:

way data

{
"requestFoundsTransports": {
"transports": [
{
"transport_participants": {
"[]": "20"
},
"transport_ammount": "1212",
"transport_details": "1ssssss"
}
]
}
}

and I need something like this:

way data

{
"requestFoundsTransports": {
"transports": [
{
"transport_participants": {
"[]": "20,21,23"
},
"transport_ammount": "1212",
"transport_details": "1ssssss"
}
]
}
}

or this way:

way data

{
"requestFoundsTransports": {
"transports": [
{
"transport_participants": {
"[0]": "20",
"[1]": "21",
"[2]": "22"
.......
},
"transport_ammount": "1212",
"transport_details": "1ssssss"
}
]
}
}

greeeeetings !!!!

Filter function

In AngularJs, it has a functionality that allow you to specify the format function for data.
https://docs.angularjs.org/api/ng/filter

For instance,

{{myData | uppercase}}

If myData='aabbcc', the content will be displayed as 'AABBCC'.

Is it possible to add such similar feature?

way.js doesn't work in Safari 7.0.6

Demos don't seem to be working in Safari 7, is it a known issue?

zrzut ekranu 2014-08-20 o 22 47 45

[Error] TypeError: 'undefined' is not a function (evaluating 'parent.matches(selector)')
    parent (way.js, line 1523)
    registerRepeats (way.js, line 417)
    registerDependencies (way.js, line 526)
    eventInit (way.js, line 1634)
    onreadystatechange (way.js, line 1556)
[Error] TypeError: 'undefined' is not a function (evaluating 'parent.matches(selector)')
    parent (way.js, line 1523)
    registerRepeats (way.js, line 417)
    registerDependencies (way.js, line 526)
    (anonymous function) (way.js, line 1607)

Works in Chrome 36, though:

zrzut ekranu 2014-08-20 o 22 48 24

Ability to change the wrapper tag

I have this problem where I want to generate a bunch of for a As it currently stands, way.js is wrapping a around the repeated items which prevents it from working with sets of data intended to go into a

I'd suggest adding a wrappertag parameter of sorts allowing to customize the tag wrapping the repeated items, instead of being hard-coded to "div".

self._bindings["__all__"] required?

I’ve tested this on Chrome v36 on OS X 10.9 and Firefox v31 on OS X 10.9, and it seems that if I do not include an element bound to "__all__", I’ll get the error: Uncaught TypeError: Cannot read property 'forEach' of undefined where undefined here refers to self._bindings["__all__"]

To elaborate, this works fine:

<html>
<body>
  <form way-data="model" way-persistent="true">
    <input type="text" name="magic">
    <input type="radio" name="ultra" value="something something darkside">
    <input type="radio" name="ultra" value="something something brightside">
  </form>
  <div way-data="__all__" way-json="true"></div>

  <script src="way.bundle.js"></script>
</body>
</html>

But this will fail:

<html>
<body>
  <form way-data="model" way-persistent="true">
    <input type="text" name="magic">
    <input type="radio" name="ultra" value="something something darkside">
    <input type="radio" name="ultra" value="something something brightside">
  </form>
  <!-- <div way-data="__all__" way-json="true"></div> -->

  <script src="way.bundle.js"></script>
</body>
</html>

Skills = `null` in demo

When I click on "add skill" in the demo I get a bunch of nulls. Tried on Firefox and Chrome.
screen shot 2014-08-21 at 15 34 08 pm

Cleanup watchers

As far as I can tell there is no documented way of cleaning up watchers. Usually in a single page app with controllers you'd like to be able to unwatch the data when the controller is destroyed. This way you avoid generating unnecessary overhead. If the watcher can't be cleaned up, a reference to that function has to stay in memory and the whole controller will never be destroyed and garbage collected. Angular solves this by returning a function that can be called to automatically unwatch that function.

Any thoughts on this?

How to do nested repeats?

I have json like

 { "services": {
        "java": {
            "package": ["java6", "java7", "java8"],
            "type": ["local", "remote"]
        },
       "php": {
            "package": ["php5-cli", "php5-fpm"],
            "type": ["local", "remote"]
        }
    }
} 

And I want to do somethink like:

 <div way-repeat="services">
         $$key
         <div way-repeat="services.package">$$key</div>                  
 </div>

And nesting can be deeper
Is it possible?

Bug: input cursor is moving when it should not

I was checking out the demo and found a bug. When you're trying to add text not tothe end of the text filed, it switches focus to the end, forcing input to occur at the end.

Steps:
First I write something in the Name field, it works. Then I want to write something to the same field, this time not to the end of it, but to the begging (or in the middle). I can type one symbol where I want it to be, but after that input cursor is moved to the end of the exising string and any successive symbols go to the end.

just a question: what will be printed under this situation

<div way-scope="someScope1">
    <div way-scope-break="true">
        <div way-data="someScope1.with.something"></div>
        <!-- Will render "hello" -->
    </div>
</div>
<script>
way.set("someScope1", {
    with: {
        something: "hello "
    }
})
</script>

I'm a little puzzled with this feature 'way-scope-break'.
I understand it this way that it will render nothing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.