Code Monkey home page Code Monkey logo

dna-engine's Issues

select data-option

Hi,
in a select, when I use data-option doesn't work. This is the error:

dna.js:672 Uncaught TypeError: Cannot read property 'option' of undefined
at updateModel (dna.js:672)

If I use data-dnaRules-option works....

Could be a bug here?

...... else if (target.is('input') || target.data().dnaRules.option)

template rendering bug ?

Hello,

i just began to "play" with dna.js, and i find it is great
but i think i may have found a bug, or at least something i do not understand.

in the attached example, ( test.txt - to be renamed as test.html )
the second template is rendered AFTER the last HR despite it is positioned before.
and more, if you remove or comment the last HR the template is not rendered at all !

tested on firefox and chromium.
reproduce problem with dna.js 1.3.4 and 1.3.7

test.txt

Use case: conditionals on array being populated

First off - I'm really liking this library so far - I find it very easy to grok!

This may be a bit off topic, and I apologise if I missed something in the docs, but how would you conditionally show or hide something based on whether an array was populated or not. I can see this is available at the field level using the data-require attribute, but what if you wanted to show a button to remove all cloned elements, but only if elements had been cloned.

Is there a way with dnajs? I'm used to angular, where this functionality is available using the native ng-show and ng-hide directives.

Cheers, Rob

Create dna.templateExists() function in dna.js

Add a new function dna.templateExists() to check if a template is present.

Below are the steps to follow to build this feature using Test-Driven Development (TDD).

1. Verify all existing tests pass

$ npm test

2. Create a test case in spec/dom.js for the new feature
Add this code:

describe('Function dna.templateExists()', () => {
   it('identifies if a template is present', () => {
      const actual =   [dna.templateExists('book'), dna.templateExists('bogus')];
      const expected = [true, false];
      assert.deepEqual(actual, expected);
      });
   });

3. Verify the new test case FAILS
The feature is not built yet, but you can still run the test case:

$ npm test

4. Create the new function in dna.js
At line 71, insert:

templateExists: (name) => {
   return !!dna.store.templates[name] || $('.dna-template#' + name).length > 0;
   },

5. Verify the new test case PASSES

$ npm test

Need new logo for dna.js open source project

Logo Design Contest

The current project logo for dna.js is pretty uninspiring and is just a placeholder until a real graphic artist creates an inspiring logo.

dnajs-logo
dnajs-logo.png

Logo Goals:

  1. Clean, simple, and modern
  2. Scalable so it looks good at different sizes
  3. Incorporation of an animal mascot would be cool (but not required)
  4. Slots nicely into the dna.js website: dnajs.org

Some words for design inspiration:
Clone, template, DNA, data, easy, clean, fast, JavaScript, HTML, jQuery

The artist who's logo is used for the project will get recognized on the dna.js website with a link to your portfolio (and if you can get to San Francisco, a drink of your choice plus an Apple Store Gift Card for a hundred dollars).

Attach your artwork to this GitHub issue. Also, feel free to post any questions or comments below.

Important Note:
dna.js is an open source project and graphics contributed to the project are licensed under MIT/GPL.

Add support for HTML5 values like "color" in type attribute of input tags

Currently data-attr-type only supports the value date. We need to add support for color, time, etc.

Example:

<input data-attr-type=color value=~~profileColor~~>

becomes

<input type=color value=#DAA520>

Note:

<input type=color value=~~profileColor~~>

results in the warning:
The specified value "~~profileColor~~" does not conform to the required format. The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers.

Use non global functions from templates

Hey guys, I was checking the docs, but I can't find a way to use a function in the data-click (or any attribute that expects a function) that is not exposed to the window object. I'm using webpack to ship my files so I don't use object namespaces (like window.MyApp.module.func). Any help is appreciated, Thanks!

Undefined variable.

dna.js: line 311, col 7, 'sessionStorage' is not defined.
dna.js: line 317, col 19, 'sessionStorage' is not defined.

Add error checking for missing data parameter

If the data field is missing when cloning a template, the current error message is very confusing. There should be an clear, explicit error message when data is undefined.

const data = undefined;
dna.clone('book', data);  //should immediately throw an error

Nesting (dots) breaks updating

Hello,

dna.js worked great for me until i tried to use nested objects. I see there is a TODO at Spec runner source code. Is it easy to implement? It would be really cool if i won't have to flatten all nested object from model to allow editing through input fields.

Thanks!

Support transform as a passed in option

Currently, data transformation functions are specified in HTML:

<div id=book class=dna-template data-transform=enhanceBook>

It might be more intuitive in JS:

dna.clone('book', books, { transform: enhanceBook });

Conditionals

Are you planning on adding new features? I'd suggest adding simple support for conditionals, something like

<div>
   <h2>Featured Books</h2>
   <div id=book class=dna-template>
      <div>Title:  <span>~~title~~</span></div>
      ~~#author?~~<div>Author: <span>~~author~~</span></div>~~/author?~~
   </div>
</div>

to check if some object is missing or empty and act in consequence.

That would be really helpful for prototyping ;)

Add support for simple (literal) arrays

It would be useful to clone from an array of simple values.

Example usage:

<div id=book class=dna-template>
   Title #<span>~~[count]~~</span>: <span>~~[value]~~</span>
</div>
dna.clone('book', ['CSS3', 'HTML5']);

result:

<div>Title #<span>1</span>: <span>CSS3</span></div>
<div>Title #<span>2</span>: <span>HTML5</span></div>

Redefinition of 'dna' on line 5.

Problem description:

[15:09:40] Starting 'default'...
[15:09:40] Finished 'default' after 15 μs
[15:09:40] Size dna.min.js : 16.06 kB
dna.js: line 5, col 5, Redefinition of 'dna'.

1 error

Problem fixed when:

There is no redefinition of dna.

Support smart update at the template level

Currently, smart update callbacks are specified at the element level:

<input value=~~title~~ data-smart-update=saveTitle>

This often necessitates annotating many input tags in the template with data-smart-update (or data-change).

It would be more convenient to annotate higher up at the template level:

<div id=book class=dna-template data-smart-update=saveBook>

The callback could be sent the clone's updated data model and the input element that triggered the update:

const saveBook = (dataModel, targetElem) => { ... }

https://dnajs.org/docs/#event-smart

Convert spec.js to ES6

convert spec.js to ES6.
-- var to let or const (as appropriate)
-- require to import (not yet supported natively in Node (not supported in V8); would need to wait for next engine or babel-ify the tests)

Add function to check if template exists

Create a new function dna.templateExists() to support checking if a template exists before cloning the template.

Example usage:

if (dna.templateExists('book'))
   dna.clone('book', { title: 'JavaScript: The Good Parts' });

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.