### Configuring start script in package.json Source: https://github.com/woowabros/woowahanjs/blob/v1/examples/hello-yarn/README.md This JSON snippet shows how to add a `start` script to the `scripts` section of your `package.json` file. This allows you to run the `webpack-dev-server` using a simpler command, `yarn start`. ```JSON "scripts": { "start": "webpack-dev-server" } ``` -------------------------------- ### Starting development server via package.json script Source: https://github.com/woowabros/woowahanjs/blob/v1/examples/hello-yarn/README.md This command executes the `start` script defined in `package.json` using Yarn. It's a convenient way to launch the webpack development server, as configured in the project's scripts. ```Shell yarn start ``` -------------------------------- ### Installing Yarn globally using npm Source: https://github.com/woowabros/woowahanjs/blob/v1/examples/hello-yarn/README.md This command installs Yarn globally on your system using npm, making the `yarn` command available from any directory. It's a prerequisite for managing project dependencies with Yarn. ```Shell npm install -g yarn ``` -------------------------------- ### Installing WoowahanJS Source: https://github.com/woowabros/woowahanjs/blob/v1/examples/hello-yarn/README.md This command adds the WoowahanJS library as a production dependency to the project. WoowahanJS is the core framework for building the application. ```Shell yarn add woowahan ``` -------------------------------- ### Running Webpack Dev Server directly Source: https://github.com/woowabros/woowahanjs/blob/v1/examples/hello-yarn/README.md This command directly executes the `webpack-dev-server` script using Yarn. It starts a local development server that serves the application and provides features like live reloading. ```Shell yarn run webpack-dev-server ``` -------------------------------- ### Installing Webpack and Webpack Dev Server Source: https://github.com/woowabros/woowahanjs/blob/v1/examples/hello-yarn/README.md This command adds Webpack and a specific version of Webpack Dev Server (v2) as development dependencies to the current project. These tools are essential for bundling assets and providing a live-reloading development environment. ```Shell yarn add --dev webpack webpack-dev-server@2 ``` -------------------------------- ### Opening application in web browser Source: https://github.com/woowabros/woowahanjs/blob/v1/examples/hello-yarn/README.md This command opens the specified URL (`http://localhost:8080/`) in the default web browser. This URL is typically where the webpack development server serves the application. ```Shell open http://localhost:8080/ ``` -------------------------------- ### Creating a Reducer for API Calls in WoowahanJS Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/action-reducer.md This snippet demonstrates creating a reducer using Woowahan.Reducer.create to handle the 'FETCH_USER_INFO' action. The reducer uses 'this.getData' to perform a GET XHR request and defines an 'onSuccess' handler to process the response and 'this.finish' to send the result back to the dispatcher. ```javascript const FETCH_USER_INFO = 'fetch-user-info'; Woowahan.Reducer.create(FETCH_USER_INFO, function(data) { this.onSuccess = function(response) { this.finish(response); }; this.getData('/api/users/'+data.userid); }); ``` -------------------------------- ### Handling Application-Level Events - Woowahan.js - JavaScript Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This snippet shows how to subscribe to application-wide events in Woowahan.js using 'app.on()'. It demonstrates listening for 'start', 'finish', and 'error' events, which are useful for implementing global behaviors like displaying toast popups, managing application state, or handling errors at a higher level. ```JavaScript var app = new Woowahan(); app.on('start', function() { // Do something console.log(app.numberOfAction()); console.log(app.numberOfWorkAction()); }); app.on('finish', function() { // Do something }); app.on('error', function(errs) { // Do something }); ``` -------------------------------- ### Handling Mouse and Keyboard Events in Woowahan.js Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This example illustrates how to capture and process mouse movement and keyboard input events in a Woowahan.js view. It shows how to log mouse coordinates (event.screenX, event.screenY) and input field values (event.target.value) within their respective event handlers. ```javascript events: { 'mousemove .canvas': 'detectMounsePosition', 'keypress .input-box': 'detectInputValue' }, detectMounsePosition(event) { console.log('x: %s, y: %s', event.screenX, event.screenY); }, detectInputValue(event) { console.log(event.target.value); } ``` -------------------------------- ### Dispatching Actions from a View in WoowahanJS Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/action-reducer.md This example shows how to dispatch an action from within a WoowahanJS view using 'this.dispatch'. It dispatches an action created by Woowahan.Action.create and specifies 'this.onReceive' as an optional handler to receive the action's processing result. ```javascript onReceive(data) { } onAction(data) { this.dispatch(Woowahan.Action.create('SearchOrders', data), this.onReceive); } ``` -------------------------------- ### HTML Structure for Parent-Child View Communication Example Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This HTML snippet defines a basic structural relationship between a parent view (.search-form within parentView) and a child view (form within childView). It serves as the markup context for demonstrating traditional and improved inter-view communication patterns in Woowahan.js. ```html
This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.
Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.
``` -------------------------------- ### Collecting Input Data with Events (Manual DOM Access) - Woowahan.js - JavaScript Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This snippet demonstrates an initial approach to collecting user input data in Woowahan.js. The 'onSearch' event handler manually retrieves the keyword from an input element using jQuery's '$el.find().val()' before dispatching a 'search' event with the collected data. ```JavaScript var childView = Woowahan.View.create('Child', { events: { 'click .btn.btn-search': 'onSearch' }, onSearch() { var keyword = this.$el.find('input[name=keyword]').val(); this.dispatch(Woowahan.Event.create('search', keyword)); } }); var parentView = Woowahan.View.create('Parent', { events: { '@search': 'onSearch' }, onSearch(keyword) { // Do something... } }); ``` -------------------------------- ### Dispatching Custom Events with Data in Woowahan.js Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This code snippet illustrates how to dispatch a custom event from a Woowahan.js view, including passing additional data. The Woowahan.Event.create helper function is used to create the event, and an object { keyword: 'javascript' } is passed as the second argument to carry event-specific data. ```javascript this.dispatch(Woowahan.Event.create('search', { keyword: 'javascript' })); ``` -------------------------------- ### Collecting Multiple Input Data with Events - Woowahan.js - JavaScript Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This snippet illustrates how to collect multiple data points from different selectors and pass them as arguments to a single event handler. By listing multiple selectors in the event definition, Woowahan.js automatically collects and provides the corresponding values to the 'onSearch' function. ```JavaScript events: { '@click .btn-search': 'onSearch(input[name=keyword], .search.option)' } onSearch(keyword, option) { // Do search } ``` -------------------------------- ### Updating WoowahanJS View Model with setModel Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view.md This JavaScript snippet demonstrates how to update a WoowahanJS view's model using the `setModel` method. It shows that `setModel` can be called multiple times, adding new keys or overwriting existing ones, while preserving other model properties. ```javascript this.setModel({ name: 'foo' }); // name=foo <- new key this.setModel({ gender: 'male' }); // name=foo, gender=male <- new key this.setModel({ name: 'bar', age: 30 }); // name=bar, gender=male, age=30 <- new & edit key ``` -------------------------------- ### Defining Action Structure in WoowahanJS Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/action-reducer.md This snippet illustrates the basic structure of an action object in WoowahanJS, consisting of a 'type' to identify the action and a 'data' object to carry payload information. This structure is fundamental for initiating tasks within the application. ```javascript { type: 'ActionName', data: { } } ``` -------------------------------- ### Decoupled Parent-Child View Communication with @Events in Woowahan.js Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This snippet demonstrates the improved, decoupled communication pattern between parent and child views using Woowahan.js's @events. The child view dispatches a custom 'search' event using this.dispatch(Woowahan.Event.create('search')), and the parent view listens for this event using '@search': 'onSearch' in its events property, eliminating HTML dependency. ```javascript var childView = Woowahan.View.create('Child', { events: { 'click .btn.btn-search': 'onSearch' }, onSearch() { this.dispatch(Woowahan.Event.create('search')); } }); var parentView = Woowahan.View.create('Parent', { events: { '@search': 'onSearch' } viewDidMount() { this.updateView('.search-form', childView); }, onSearch() { // Do something... } }); ``` -------------------------------- ### Handlebars Template for Woowahan.js Data Binding Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view-model.md This Handlebars template illustrates Woowahan.js one-way data binding using `data-role="bind"` and `data-name` attributes. It binds a button's label to `buttonLabel` and a time element's content to `time`, allowing UI updates when the model changes. ```handlebars ``` -------------------------------- ### Retrieving Full WoowahanJS View Model Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view.md This JavaScript snippet illustrates how to retrieve the entire model object from a WoowahanJS view using `this.getModel()` without any arguments. The returned value is a pure JavaScript object representing the current state of the view's model. ```javascript var model = this.getModel(); /* model = { name: 'bar', gender: 'male', age: 30 } */ ``` -------------------------------- ### Traditional Parent-Child View Communication in Woowahan.js Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This JavaScript snippet shows a traditional approach to parent-child view communication in Woowahan.js where the parent view directly handles a DOM event (click .btn.btn-search) originating from the child view's HTML. It demonstrates viewDidMount for view updates but highlights the tight HTML dependency between parent and child. ```javascript var childView = Woowahan.View.create('Child', { }); var parentView = Woowahan.View.create('Parent', { events: { 'click .btn.btn-search': 'onSearch' }, viewDidMount() { this.updateView('.search-form', childView); }, onSearch() { // Do something... } }); ``` -------------------------------- ### Manipulating DOM in viewDidMount with jQuery Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view.md This JavaScript snippet demonstrates how to interact with the view's DOM after rendering is complete using the `viewDidMount` lifecycle method. The `$el` argument is a jQuery object representing the view's root DOM element, allowing full use of jQuery functionalities. ```javascript viewDidMount($el) { $el.find('.switch').toggleClass('on'); } ``` -------------------------------- ### Modifying View State Before Rendering in Woowahan.js Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view-model.md This Woowahan.js view demonstrates how to modify or inject state into `renderData` using the `viewWillMount` lifecycle hook. It calculates if `today` is a holiday and adds a `holiday` property to `renderData`, which is then used by the template. It also highlights that `renderData` is temporary and not part of the persistent model after rendering. ```javascript import Template from './myview.hbs'; Woowahan.View.create('MyView', { template: Template, initialize() { this.setModel({ today: '2001-10-21' }); this.super(); }, viewWillMount(renderData) { let today = new Date(this.getModel('today')); let day = today.getDay(); if (day === 0 || day === 6) { renderData.holiday = true; } else { renderData.holiday = false; } return renderData; }, viewDidMount($el) { console.log(this.getModel('holiday')); /* undefined */ } }); ``` -------------------------------- ### Incorrect viewWillMount: Missing Return Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view.md This JavaScript snippet illustrates an incorrect usage of `viewWillMount` where the modified `renderData` is not returned. Without returning `renderData`, any changes made within the method will not be reflected in the view's rendering. ```javascript viewWillMount(renderData) { renderData.name = `이름은 ${renderData.name}`; } ``` -------------------------------- ### Correctly Modifying Render Data in viewWillMount Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view.md This JavaScript snippet demonstrates the correct way to modify `renderData` within the `viewWillMount` lifecycle method. It shows how to update a property of the `renderData` object and then return the modified object to ensure changes are applied during rendering. ```javascript viewWillMount(renderData) { renderData.name = `이름은 ${renderData.name}`; return renderData; } ``` -------------------------------- ### Correctly Modifying WoowahanJS View Model Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view.md This JavaScript snippet highlights the correct way to modify a WoowahanJS view's model using `this.setModel()`. It contrasts this with an incorrect approach where direct manipulation of a `getModel()` return value does not update the view's internal model. ```javascript var model = this.getModel(); model.name = 'foo'; // 뷰 모델 name 값은 변경되지 않습니다. this.setModel({ name: 'foo' }); // 뷰 모델 name 값이 'foo'로 변경됩니다. ``` -------------------------------- ### Receiving Custom Child View Events in Woowahan.js Parent View Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This snippet shows the syntax for a parent view to receive custom events dispatched by its child views in Woowahan.js. By prefixing the event name with '@' (e.g., '@search'), the parent view's onSearch handler will be invoked when the child dispatches the 'search' event. ```javascript events: { '@search': 'onSearch' } ``` -------------------------------- ### Handlebars Template for Conditional Class and Data Display Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view-model.md This Handlebars template defines a `time` element that conditionally applies a `holiday` class based on the `holiday` model property and displays the `today` model property. It's designed to be used with a Woowahan.js view that injects data before rendering. ```handlebars ``` -------------------------------- ### Receiving Custom Child View Events with Selector in Woowahan.js Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/event.md This snippet demonstrates how to receive custom events from a specific child view instance when multiple child views are present or when a selector is needed for clarity. By including the selector (e.g., .search-form) after the @event name, the event handler will only be triggered for events dispatched by the child view mounted to that specific container. ```javascript events: { '@search .search-form': 'onSearch' } ``` -------------------------------- ### Retrieving Current CollectionView Data Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/collection-view.md This snippet demonstrates how to use the `getCollection` method to retrieve the current collection data managed by the CollectionView. This method always returns the most up-to-date data in JSON format, even if individual `rowView` instances have modified their view models. ```javascript // 현재 rowView들이 가진 뷰 모델 리스트를 가져옵니다. console.log(this.getCollection()); ``` -------------------------------- ### Defining a Large Font Size in CSS Source: https://github.com/woowabros/woowahanjs/blob/v1/examples/route/index.html This CSS snippet defines a class named 'big' that sets the font size to 50 pixels. It can be applied to HTML elements to increase their text size significantly. ```CSS .big { font-size: 50px; } ``` -------------------------------- ### Incorrect viewWillMount: Direct Model Modification Source: https://github.com/woowabros/woowahanjs/blob/v1/docs/view.md This JavaScript snippet shows an incorrect way to modify data within `viewWillMount` by directly calling `this.setModel()`. While `this.setModel()` changes the view's internal model, these changes will not be reflected in the current rendering cycle because `viewWillMount` operates on a copy of the model (`renderData`). ```javascript viewWillMount(renderData) { this.setModel({ name: `이름은 ${renderData.name}` }); return renderData; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.